Dynamic Stacked Area Chart

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
Cambridge
Posts: 1
Joined: Mon Jul 09, 2012 11:24 pm
antibot: No, of course not.

Dynamic Stacked Area Chart

Post by Cambridge » Mon Jul 09, 2012 11:33 pm

Dynamic Stacked Area Chart

The following is a link to a web page with a demo of a
stacked area chart:

http://www.java2s.com/Code/Java/Chart/J ... rtDemo.htm

Image

The code is provided, but it's for a static CategoryDataset, created
using DatasetUtilities.createCategoryDataset(...).

It's a great example, but I need to be able to change the graph
dynamically. The CategoryDataset doesn't let you change anything.

Is there any way to make this dynamic?

If there's no way to change the dataset, is there any way to make
a call that replaces the dataset entirely in the chart?

Thanks,

John

John Matthews
Posts: 513
Joined: Wed Sep 12, 2007 3:18 pm

Re: Dynamic Stacked Area Chart

Post by John Matthews » Tue Jul 10, 2012 3:31 am

One of my favorite things about JFreeChart is linksource="yes" in build.xml, but I digress. Internally, DatasetUtilities.createCategoryDataset() constructs a DefaultCategoryDataset, which is eminently mutable. I'd say cast the return value or construct your own.

reivilo59
Posts: 3
Joined: Mon Jan 19, 2015 3:32 pm
antibot: No, of course not.

Re: Dynamic Stacked Area Chart

Post by reivilo59 » Tue Jan 20, 2015 5:05 pm

Hi,

I have the same problem, and I don't find any solution.
Have you find a solution for dynamic stacked area chart ?

Thank's

John Matthews
Posts: 513
Joined: Wed Sep 12, 2007 3:18 pm

Re: Dynamic Stacked Area Chart

Post by John Matthews » Sat Jan 24, 2015 5:15 pm

I started from the example cited and cast the dataset as suggested:

Code: Select all

DefaultCategoryDataset dataset = (DefaultCategoryDataset) createDataset();
I added a suitable Action:

Code: Select all

add(chartPanel);
add(new JButton(new AbstractAction("Add") {

	@Override
	public void actionPerformed(ActionEvent e) {
		dataset.addValue(Math.random() * 42, "Row", "Added");
	}
}), BorderLayout.PAGE_END);
I see a result similar to this image:
Image

Locked