I’m evaluating chart libraries to my next project and I’m trying to do a simple chart like the one in the attached image.
It was actually very easy to do it using MPAndroidChart, however it’s been hard to do a simple task like put a label aligned with the column… I did take a look into the SciChart sample application, but the application just uses numeric labels…
Can someone provide some guidance of how to do this?
- Nelson Glauber asked 4 years ago
- last edited 4 years ago
- You must login to post comments
Hi Nelson,
To add label on top of column I would suggest to use TextAnnotation for each value that you need to display text for.
final TextAnnotation textAnnotation = sciChartBuilder.newTextAnnotation()
.withX1(0.3)
.withY1(9.7)
.withText("9.7")
// use anchor point to center annotation horizontally above specified point
.withHorizontalAnchorPoint(HorizontalAnchorPoint.Center)
.withVerticalAnchorPoint(VerticalAnchorPoint.Bottom)
.build();
Collections.addAll(surface.getAnnotations(), textAnnotation);
Is this suitable for your needs?
Best regards,
Yura
- Yura Khariton answered 4 years ago
- You must login to post comments
Hi Yura,
I have currently a few problems with I’m struggling to resolve:
1. How can I rotate 45 degrees the texts below the columns?
2. How can I detect the click on each bar?
3. How can I display the value just above the column/bar?
Regarding your answer, how can I know the column position to set the text X,Y position?
I’m attaching an image with my current result.
- Nelson Glauber answered 4 years ago
-
I’m afraid that we don’t support #1 for now ( it would require rewriting of code which is responsible for rendering of axis). For #2 it depends on what you’re trying to achieve. We provide ChartModifier API (https://www.scichart.com/documentation/android/current/webframe.html#What%20is%20a%20ChartModifier.html) which is responsible for interaction with chart (e.g. displaying tooltips, legend, zooming, panning chart etc ). If you want to implement something custom you can create custom ChartModifier(https://www.scichart.com/documentation/android/current/webframe.html#Custom%20Modifiers%20-%20ChartModifierBase%20API.html). The other approach is to override onTouch() method of chart and use HitTest API like in one of our examples (https://www.scichart.com/example/android-chart-example-hit-test-api/). For #3 I believe you need to add TooltipModifier(https://www.scichart.com/documentation/android/current/webframe.html#TooltipModifier.html). Regarding your last question about text – well you can create annotation in for loop which you use to you fill up your data series. So for each point appended into data series you create annotation with same X and Y values as point that you appended, then add it into chart. For more information please take a look on tutorial from our documentation ( https://www.scichart.com/documentation/android/current/webframe.html#Tutorial%2007%20-%20Adding%20Annotations.html )
- You must login to post comments
Please login first to submit.