In a real muddle.

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Post Reply
Posts: 8
Joined: Mon Aug 19, 2019 7:29 pm
antibot: No, of course not.

In a real muddle.

Post by dgarratt » Wed Aug 21, 2019 1:38 pm

I have a desktop swing application to which I've added a JFreeChart Panel. I have a routine which builds a DefaultXYDataset by using 2 arrays of double. SeqDates was going to show the times for samples but to simplify it's just a sequential number starting at one and incrementing by 1 for each new graphMeans entry. graphMeans is is mean weight of a number of samples.

DefaultXYDataset result = new DefaultXYDataset();

double[] SeqDates = new double[count];
double[] graphMeans = new double[count];

SeqDates = 1.0, 2.0 etc
graphMeans = 102.5,103.7

double[][] series1 ={ SeqDates, graphMeans };

result.addSeries("mean", series1);

I got it working but I was having 2 problems. The most important problem is that every 15 mins I need to add a new value to the arrays

SeqDates = 1.0, 2.0 ,3.0etc
graphMeans = 102.5,103.7,101.2

What I need to be able to do is adjust the range of the verticle axis to make sure that it still encompasses the min and max values of the graphMeans and the x axis to that it shows in this case 3 entries instead of 2.

I've been fumbling around with bits of code examples off the internet but I'm too ashamed to show you what i've ended up with. My first version seemed to work until I clicked on the graph by mistake and it seemed to revert to an ealier form. Another version would not update with the additional values at all.

The API is just a bit too complex for me to get my head around and the examples I've found on the net so far don't seem to fit with what I think should be a simple requirement.

chart = ChartFactory.createXYLineChart("Weights Graph", "Sample", "Mean Weight",result , PlotOrientation.VERTICAL, true, true, false);

NumberAxis rangeAxis = new NumberAxis("Weight");
rangeAxis.setRange(highestvalueingraphMeans, lowestvalueingraphMeans );


// This bit is wrong. Should be updating and not recreating.
cp = new ChartPanel(chart);

cp.setBounds(14, 178, 746, 374);


Post Reply