Hi!
I have generated a simple chart.
@Getter
public class LineChart extends AbstractChart {
/**
*
*/
private static final long serialVersionUID = 1L;
private Chart chart;
@Override
public void initDemo() {
chart = new Chart();
chart.setWidth("1027px");
chart.setHeight("768px");
Configuration configuration = chart.getConfiguration();
configuration.setTitle("Analog signals");
configuration.setSubTitle("jlogger");
YAxis yAxis = configuration.getyAxis();
yAxis.setTitle("Measurements");
Legend legend = configuration.getLegend();
legend.setLayout(LayoutDirection.VERTICAL);
legend.setVerticalAlign(VerticalAlign.MIDDLE);
legend.setAlign(HorizontalAlign.RIGHT);
// Add 20 data points
configuration.addSeries(new ListSeries("ADC0", 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0));
configuration.addSeries(new ListSeries("ADC1", 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0));
configuration.addSeries(new ListSeries("ADC2", 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0));
configuration.addSeries(new ListSeries("ADC3", 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0));
configuration.addSeries(new ListSeries("ADC4", 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0));
configuration.addSeries(new ListSeries("ADC5", 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0));
add(chart);
}
}
And I pick up the object chart
in another class. I want to chenge the ListSeries
object inside chart.
// Get the series from the chart too
@SuppressWarnings("unchecked") // Need to have this due to the cast (ListSeries)
ADC0 = (ListSeries) lineChart.getChart().getConfiguration().getSeries().get(0);
ADC1 = (ListSeries) lineChart.getChart().getConfiguration().getSeries().get(1);
ADC2 = (ListSeries) lineChart.getChart().getConfiguration().getSeries().get(2);
ADC3 = (ListSeries) lineChart.getChart().getConfiguration().getSeries().get(3);
ADC4 = (ListSeries) lineChart.getChart().getConfiguration().getSeries().get(4);
ADC5 = (ListSeries) lineChart.getChart().getConfiguration().getSeries().get(5);
When I change the list series inside chart
object, then it looks like this.
ADC0.addData(adcValues[0]
, true, true); // Update updateChartImmediately = true, shift to left = true
ADC1.addData(adcValues[1]
, true, true);
ADC2.addData(adcValues[2]
, true, true);
ADC3.addData(adcValues[3]
, true, true);
ADC4.addData(adcValues[4]
, true, true);
ADC5.addData(adcValues[5]
, true, true);
Then my chart looks like this. At the beginning I have 20 points, all zeros.
And after few seconds, The chart looks like this.
Isn’t it meant that this .addData(Number, updatedirectly, shift)
should add a number to the ListSeries
and then remove the first one? As I see, only the 20th number will be replaced with the latest number, while the ListSeries
become smaller and smaller.
How can I solve this?