AnyChart / AnyChart-Android

AnyChart Android Chart is an amazing data visualization library for easily creating interactive charts in Android apps. It runs on API 19+ (Android 4.4) and features dozens of built-in chart types.
2.31k stars 369 forks source link

Multiple Series in Column Chart #30

Closed rafvasq closed 6 years ago

rafvasq commented 6 years ago

Assuming it's possible, is there a sample to follow to implement multiple data series on a column chart? I've seen the samples and documentation for JavaScript, but I do not see any for Android.

https://docs.anychart.com/Basic_Charts/Column_Chart#multiple_series

Thanks!

Shestac92 commented 6 years ago

@rafvasq Yes, this is possible using the Android library too. Here is a sample:

Cartesian chart = AnyChart.column();

List<DataEntry> data = new ArrayList<>();
data.add(new CustomDataEntry("John", 10000, 12500));
data.add(new CustomDataEntry("Jake", 12000, 15000));
data.add(new CustomDataEntry("Peter", 13000, 16500));
data.add(new CustomDataEntry("James", 10000, 13000));
data.add(new CustomDataEntry("Mary", 9000, 11000));

Set set = new Set(data);

Mapping mapping = set.mapAs("{ x: 'x', value: 'value' }");
Mapping mapping2 = set.mapAs("{ x: 'x', value: 'value2' }");

CartesianSeriesColumn series1 = chart.column(mapping);
series1.setName("Sales in 2015");

CartesianSeriesColumn series2 = chart.column(mapping2);
series2.setName("Sales in 2016");

chart.setBarsPadding(-0.5);

chart.setBarGroupsPadding(2);

chart.setTitle("Column Chart: Padding (Multiple Series)");

chart.getXAxis().setTitle("Manager");
chart.getYAxis().setTitle("Sales, $");

anyChartView.setChart(chart);

CustomDataEntry:

private class CustomDataEntry extends ValueDataEntry {
    CustomDataEntry(String x, Number value, Number value2) {
        super(x, value);
        setValue("value2", value2);
    }
}
rafvasq commented 6 years ago

It looks like most of the code sample you provided does not work with AnyChart's newest releases (1.0.0 and 1.0.1).

Can you please update it?

Shestac92 commented 6 years ago

@rafvasq Yes, the latest update brings many positive changes and new features. Here is the modified sample based on the latest version of the library:

AnyChartView anyChartView = findViewById(R.id.any_chart_view);
anyChartView.setProgressBar(findViewById(R.id.progress_bar));

Cartesian cartesian = AnyChart.column();

List<DataEntry> data = new ArrayList<>();
data.add(new CustomDataEntry("John", 10000, 12500));
data.add(new CustomDataEntry("Jake", 12000, 15000));
data.add(new CustomDataEntry("Peter", 13000, 16500));
data.add(new CustomDataEntry("James", 10000, 13000));
data.add(new CustomDataEntry("Mary", 9000, 11000));

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

Mapping mapping = set.mapAs("{ x: 'x', value: 'value' }");
Mapping mapping2 = set.mapAs("{ x: 'x', value: 'value2' }");

Column series1 = cartesian.column(mapping);
series1.name("Sales in 2015");

Column series2 = cartesian.column(mapping2);
series2.name("Sales in 2016");

cartesian.barsPadding(-0.5);

cartesian.barGroupsPadding(2);

cartesian.title("Column Chart: Padding (Multiple Series)");

cartesian.xAxis(0).title("Manager");
cartesian.yAxis(0).title("Sales, $");

anyChartView.setChart(cartesian);
tomgallagher commented 5 years ago

Hello - could you tell me where the API reference docs for Android are? Everything seems to be Javascript