I'm working on a project using SWTChart in Eclipse, and I need to update the series data and legend dynamically based on user selection.
Problem
I've created a chart using SWTChart, and I want to update the series data and legend when the user makes a specific selection. Here's a snippet of my current code:
How can I dynamically update the series data and legend in SWTChart based on user selection? Any guidance or examples would be greatly appreciate
private void createMiniLineChart(Chart lineChart, double[] seriesdata, String graphID) {
// set titles
lineChart.getTitle().setText(EZPDContants.EMPTY_STRING);
lineChart.getAxisSet().getXAxis(0).getTitle().setVisible(false);
lineChart.getAxisSet().getYAxis(0).getTitle().setVisible(false);
ISeries series = (ILineSeries<?>) lineChart.getSeriesSet().createSeries(SeriesType.LINE, graphID);
series.setXSeries(seriesdata);
// adjust the axis range
lineChart.getAxisSet().adjustRange();
// hide the x and y axis
lineChart.getAxisSet().getXAxis(0).getTick().setVisible(false);
lineChart.getAxisSet().getYAxis(0).getTick().setVisible(false);
//Hide the default legend provided by SWTChart.
lineChart.getLegend().setVisible(false);
// Set the chart layout data
lineChart.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
// Draw the border
lineChart.setForeground(lineChart.getDisplay().getSystemColor(SWT.COLOR_BLACK));
lineChart.setBackground(lineChart.getDisplay().getSystemColor(SWT.COLOR_WHITE));
lineChart.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
lineChart.addMouseListener(new MouseAdapter() {
@Override
public void mouseDown(MouseEvent e) {
System.out.println("Mouse double-clicked!");
refreshGraphTemp();
System.out.println(seriesdata);
}
});
createCustomLegend(lineChart.getParent(), graphID);
// Set the chart redraw flag
lineChart.setRedraw(true);
}
private void refreshGraphTemp() {
//lineChart.getSeriesSet().clear();
series.setXSeries(seriesMaindata);
//cleare legend
//lineChart.getLegend().
lineChart.getAxisSet().adjustRange();
lineChart.setRedraw(true);
}