-
Notifications
You must be signed in to change notification settings - Fork 370
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
How to reload chart with new data? #28
Comments
@trungdn0401 |
@Shestac92 //test new data
Button btnAbc = findViewById(R.id.btnAbc);
btnAbc.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
List<DataEntry> test = new ArrayList<>();
test.add(new CustomDataEntry("Espresso", 1, 2, 3, null, null, null));
test.add(new CustomDataEntry("Doppio", 2, null, null, null, null, null));
test.add(new CustomDataEntry("Trippio", 3, null, null, null, null, null));
test.add(new CustomDataEntry("Americano", 1, 3, null, null, null, null));
test.add(new CustomDataEntry("Cappuchino", 1, null, 1, 2, null, null));
test.add(new CustomDataEntry("Macchiato", 2.5, null, null, 1, null, null));
test.add(new CustomDataEntry("Latte", 1, null, 2, 1, null, null));
test.add(new CustomDataEntry("Latte Macchiato", 1, null, 2, null, 1, null));
test.add(new CustomDataEntry("Vienna Coffee", 1, null, null, null, 2, null));
test.add(new CustomDataEntry("Mocco", 1, null, 1, null, 1, 1));
column3d.setData(test);
}
}); |
@trungdn0401 |
@trungdn0401 private Set set;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_chart_common);
AnyChartView anyChartView = findViewById(R.id.any_chart_view);
Cartesian3d column3d = AnyChart.column3d();
column3d.yScale().stackMode(ScaleStackMode.VALUE);
column3d.title("Types of Coffee");
column3d.title().padding(0d, 0d, 15d, 0d);
List<DataEntry> seriesData = new ArrayList<>();
seriesData.add(new CustomDataEntry("Espresso", 1, null, null, null, null, null));
set = Set.instantiate();
set.data(seriesData);
Mapping series1Data = set.mapAs("{ x: 'x', value: 'value' }");
Column3d series1 = column3d.column(series1Data);
series1.name("Espresso");
series1.fill(new SolidFill("#3e2723", 1d));
series1.stroke("1 #f7f3f3");
series1.hovered().stroke("3 #f7f3f3");
column3d.legend().enabled(true);
column3d.legend().fontSize(13d);
column3d.legend().padding(0d, 0d, 20d, 0d);
column3d.yScale().ticks("[0, 1, 2, 3, 4, 5]");
column3d.xAxis(0).stroke("1 #a18b7e");
column3d.xAxis(0).labels().fontSize("#a18b7e");
column3d.yAxis(0).stroke("1 #a18b7e");
column3d.yAxis(0).labels().fontColor("#a18b7e");
column3d.yAxis(0).labels().format("{%Value}{groupsSeparator: }");
column3d.yAxis(0).title().enabled(true);
column3d.yAxis(0).title().text("Portions of Ingredients");
column3d.yAxis(0).title().fontColor("#a18b7e");
column3d.interactivity().hoverMode(HoverMode.BY_X);
column3d.tooltip()
.displayMode(TooltipDisplayMode.UNION)
.format("{%Value} {%SeriesName}");
column3d.yGrid(0).stroke("#a18b7e", 1d, null, null, null);
column3d.xGrid(0).stroke("#a18b7e", 1d, null, null, null);
anyChartView.setChart(column3d);
Button btnAbc = findViewById(R.id.btnAbc);
btnAbc.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
List<DataEntry> seriesData = new ArrayList<>();
seriesData.add(new CustomDataEntry("Espresso", new Random().nextInt(10), new Random().nextInt(10), new Random().nextInt(10), null, null, null));
set.data(seriesData);
}
});
} |
@Shestac92 And, Is there any ways to fixed column width of chart above pls? |
@trungdn0401 Padding is measured as a ratio to the width of columns (the width is calculated automatically). So, if it is < 1, the space between columns or column groups is less than the width of columns, and vice versa. If padding is set to 0, there is no space between columns/groups, and a negative parameter makes columns overlap each other. |
Hello @Shestac92 , |
@trungdn0401 |
|
// remove old chart
anyChartView.clear();
// and only than create a new chart and add to the view
Pie pie = AnyChart.pie();
List<DataEntry> data = new ArrayList<>();
data.add(new ValueDataEntry("Apples", 6371664));
data.add(new ValueDataEntry("Pears", 789622));
pie.data(data);
anyChartView.setChart(pie); |
@Shestac92 Hi @Shestac92 , It's OK if I does not clear, just setChart. Thank you! |
Hi @Shestac92 , |
@trungdn0401 @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_chart_common);
AnyChartView anyChartView = findViewById(R.id.any_chart_view);
Cartesian column = AnyChart.column();
List<DataEntry> seriesData = new ArrayList<>();
seriesData.add(new CustomDataEntry("1990", 10, 40, 10));
seriesData.add(new CustomDataEntry("1991", 40, 5, 50));
seriesData.add(new CustomDataEntry("1992", 80, 50, 30));
seriesData.add(new CustomDataEntry("1993", 80, 20, 90));
seriesData.add(new CustomDataEntry("1994", 40, 80, 85));
seriesData.add(new CustomDataEntry("1995", 15, 50, 60));
Set set = Set.instantiate();
set.data(seriesData);
Mapping series1Data = set.mapAs("{ x: 'x', value: 'value' }");
Mapping series2Data = set.mapAs("{ x: 'x', value: 'value2' }");
Mapping series3Data = set.mapAs("{ x: 'x', value: 'value3' }");
Column series1 = column.column(series1Data);
series1.name("Company 1")
.color("#00ff00");
Column series2 = column.column(series2Data);
series2.name("Company 2")
.color("#0000ff");
Column series3 = column.column(series3Data);
series3.name("Company 3")
.color("#ffff00");
column.xAxis(0).orientation(Orientation.TOP)
.stroke(null)
.ticks(false);
column.xGrid(0).enabled(true);
column.legend(true);
column.legend()
.position(Orientation.RIGHT)
.itemsLayout(LegendLayout.VERTICAL);
anyChartView.setChart(column);
}
private class CustomDataEntry extends ValueDataEntry {
CustomDataEntry(String x, Number value, Number value2, Number value3) {
super(x, value);
setValue("value2", value2);
setValue("value3", value3);
}
} |
Hi,
|
Hi everybody. When I use the code in fragment then It's not working when the add new data |
@Shestac92 I can't reload new data when it's action in fragment class. please help me. thanks so much |
It does not work for me. |
Hi, i'm using vertical chart. the data doesn't update after changing from API. Thanks |
Same issue |
Hi,
I'm using trial version, how to reload chart with new data?
Thanks!
The text was updated successfully, but these errors were encountered: