I'm having issues with refreshing/repainting a BarChart after setting a zero value of a CategoryDataset to a very large number.
private class Test
extends ApplicationFrame {
private DefaultCategoryDataset set;
public Test(
String newTitle) {
super(newTitle);
set = new DefaultCategoryDataset();
set.addValue(0, "Test", "1");
JFreeChart barChart = ChartFactory.createBarChart(
"Test",
"Category",
"Score",
set,
PlotOrientation.VERTICAL,
true,
true,
false);
JPanel mainPanel = new JPanel(new GridLayout());
ChartPanel chartPanel = new ChartPanel(barChart);
chartPanel.setPreferredSize(new java.awt.Dimension(560, 367));
mainPanel.add(chartPanel);
JButton b = new JButton();
createDataset();
b.addActionListener(e -> {
set.setValue(Integer.MAX_VALUE, "Test", "1");
});
mainPanel.add(b);
setContentPane(mainPanel);
pack();
setVisible(true);
}
Here is the chart with a zero value.
Setting the value to a very large number.
Clicking inside the chart.
How can the chart be properly refreshed? I've tried to repaint the ChartPanel, but it hasn't worked.