AnyChart coloring grid on Android

shtas :

Im implementing AnyChart LineChart in my Android app and struggling to display coloured grid.

What I'd like to achieve in terms of the background (not a chart type) is: https://playground.anychart.com/docs/v8/samples/AGST_Axes_Basic_11

I manage to display the data however as soon as I put the code responsible for coloring the grid the chart is not displayed. Here's the code:

    String[] rangeColors = new String[] {"#ff0000", "#00ff00"};
    cartesian.yGrid(0).palette(rangeColors);
    cartesian.yGrid(0).palette().count(10);
    cartesian.yScale().minimum(390).maximum(859);
    cartesian.yScale().ticks().interval(10);

If I remove the line:

cartesian.yGrid(0).palette().count(10);

Then the chart displays with the yGrid coloured but it's green and red intertwined in a way one interval is green next red then again green and so on.

Rest of the code related to the chart comes from the example: https://github.com/AnyChart/AnyChart-Android/blob/master/sample/src/main/java/com/anychart/sample/charts/LineChartActivity.java The only difference is Im having only 1 data series instead of 3.

Could anyone help me get the example work in Android?

AnyChart Support :

The gradient steps count feature is provided by RangeColors class, so you should use this class instead of Palette. That's why calling count(10) leads to an exception.

The code below describes how to achieve the required coloring:

        RangeColors palette = RangeColors.instantiate();
        palette.items("#ff0000", "#00ff00");
        palette.count(10);
        cartesian.yGrid(0).palette(palette);

The result on the screenshot below: Result

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=126777&siteId=1