Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

change Legend name in Cartesian chart #188

Closed
GauravCreed opened this issue Aug 6, 2020 · 6 comments
Closed

change Legend name in Cartesian chart #188

GauravCreed opened this issue Aug 6, 2020 · 6 comments

Comments

@GauravCreed
Copy link

Hi @chidori

Screenshot_1596713546

How can i change series name in legend and as well as in tooltip.
for legend enable i usecartesian.legend().align(Align.CENTER).enabled(true);

Capture
Capture2

is there any solution for this then help me.
Thanks(_).

@Shestac92
Copy link

@GauravCreed
To achieve that apply a series name using name() method of the series.
For details, check the snippet below:

        AnyChartView anyChartView = findViewById(R.id.any_chart_view);
        Cartesian chart = AnyChart.line();

        List<DataEntry> data = new ArrayList<>();
        data.add(new ValueDataEntry("John", 10.345234525));
        data.add(new ValueDataEntry("Jake", 12.13451345));
        data.add(new ValueDataEntry("Peter", 18.4567465));
        data.add(new ValueDataEntry("Mike", 14.23457234));

        Column series = chart.column(data);

        // apply series name
        series.name("Sales");
        chart.legend().align(Align.CENTER).enabled(true);

        anyChartView.setChart(chart);

Below is the result:
sample

@GauravCreed
Copy link
Author

GauravCreed commented Aug 7, 2020

Hi @chidori

Thanks for quick answer.

As per your answer it is possible, but on bar chart only one data display, see my image i want the multiple data on single bar chart column. is it possible ? got my point?

89527341-cda88c00-d806-11ea-8fce-1d6af83da0f2

Thanks(_)

@Shestac92
Copy link

@GauravCreed
Yes, absolutely the same approach is available for multiple series.
To be precise, can you provide the chart configuration code? I will modify it to show how it works with multiple series.

@GauravCreed
Copy link
Author

Hi @chidori

private void setupChartData() {
    Cartesian cartesian = AnyChart.cartesian();
    cartesian.animation(true);
    cartesian.title("All Devotion Progress");
    cartesian.yScale().stackMode(ScaleStackMode.VALUE);

    Linear scalesLinear = Linear.instantiate();
    scalesLinear.minimum(0d);
    scalesLinear.maximum(100d);
    scalesLinear.ticks("{ interval: 10 }");

    com.anychart.core.axes.Linear extraYAxis = cartesian.yAxis(1d);
    extraYAxis.orientation(Orientation.LEFT).scale(scalesLinear);
    extraYAxis.labels().padding(0d, 0d, 0d, 5d).format("{%Value}");

    cartesian.xAxis(0).orientation(Orientation.BOTTOM);

    List<DataEntry> data = new ArrayList<>();
    data.add(new CustomDataEntry("Sunday", 0, 2040, 1200, 1600));
    data.add(new CustomDataEntry("Monday", 0, 1794, 1124, 1724));
    data.add(new CustomDataEntry("Tuesday", 0, 2026, 1006, 1806));
    data.add(new CustomDataEntry("Wednesday", 0, 2341, 921, 1621));
    data.add(new CustomDataEntry("Thursday", 0, 1800, 1500, 1700));
    data.add(new CustomDataEntry("Friday", 0, 1507, 1007, 1907));
    data.add(new CustomDataEntry("Saturday", 0, 2701, 921, 1821));*/

    Set set = Set.instantiate();
    set.data(data);

    cartesian.legend().align(Align.CENTER).enabled(true);

    Mapping lineData = set.mapAs("{ x: 'x', value: 'value' }");
    Mapping column1Data = set.mapAs("{ x: 'x', value: 'value2' }");
    Mapping column2Data = set.mapAs("{ x: 'x', value: 'value3' }");
    Mapping column3Data = set.mapAs("{ x: 'x', value: 'value4' }");

    Line line = cartesian.line(lineData);
    line.yScale(scalesLinear);

    cartesian.column(column1Data);
    cartesian.column(column2Data);
    cartesian.column(column3Data);

    cartesian.crosshair(false);
    cartesian.tooltip().positionMode(TooltipPositionMode.POINT);

    /*Marker series1 = cartesian.marker(column1Data);
    series1.name(getResources().getString(R.string.menuDevotion)).enabled(false);

    Marker series2 = cartesian.marker(column2Data);
    series2.name(getResources().getString(R.string.menu_word_devotion)).enabled(false);

    Marker series3 = cartesian.marker(column2Data);
    series3.name(getResources().getString(R.string.menu_morning_evening_devotion)).enabled(false);*/

    anyChartView.setChart(cartesian);
}

see that line

data.add(new CustomDataEntry("Sunday", 0, 2040, 1200, 1600));
i added second argument as 0 b'coz i don't want line in chart

Thanks(_)

@Shestac92
Copy link

@GauravCreed
In your snippet you create three column series like this:

    cartesian.column(column1Data);
    cartesian.column(column2Data);
    cartesian.column(column3Data);

To apply series names modify the code like this:

    cartesian.column(column1Data).name("My name 1");
    cartesian.column(column2Data).name("My name 2");
    cartesian.column(column3Data).name("My name 3");

@GauravCreed
Copy link
Author

Hey @Shestac92

Thanks a lot,it's resolve my problem.
Thanks(_).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants