Concatenate values in the JFreeChart chart

2

How to concatenate values in jfreechart?

I'm trying this way:

public static DefaultCategoryDataset dataset = new DefaultCategoryDataset();;

    public void atualizaDataset(int humano, int zumbi, int rodada){
        final String series1 = "Humano";
        final String series2 = "Zumbi";

        dataset.addValue(humano, series1, (Comparable)rodada);
        dataset.addValue(zumbi, series2, (Comparable)rodada);
    }

But I am not succeeding, it executes the first time I send it, but when I send the second it adds as if it were the first values, they do not concatenate!

    
asked by anonymous 26.11.2015 / 15:35

1 answer

1

You can do the following, create a constructor that gets a CategoryDataset

public LineChartDemo1(final String title, CategoryDataset dataset) {
        super(title);
        final CategoryDataset dataset = dataset;
        final JFreeChart chart = createChart(dataset);
        final ChartPanel chartPanel = new ChartPanel(chart);
        chartPanel.setPreferredSize(new Dimension(500, 270));
        setContentPane(chartPanel);
}

and its main() :

 DefaultCategoryDataset dataset = new DefaultCategoryDataset();
//adiciona valores aqui
final LineChartDemo1 demo = new LineChartDemo1("Line Chart Demo", dataset);
//resto do código

If you add after you have built the graph, you will need to repaint it.

    
26.11.2015 / 17:44