Empty Chart

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
Ted Hill

Empty Chart

Post by Ted Hill » Tue Aug 20, 2002 7:39 pm

Hello,

I'm putting up a panel that will have a couple of XY plots on it. When it first comes up, there is no data, so I want to display a couple of empty charts as place holders on the panel.

This is the code that I'm currently using:
====================================================
public static JPanel makeEmptyChartPanel()
{
EmptyXYDataset dataset = new EmptyXYDataset();

JFreeChart chart = ChartFactory.createXYChart(
"", // title at the top of chart
"", // label for x axis
"", // label for y axis
dataset, // the data
false); // true if want legend


ChartPanel chartPanel = new ChartPanel(chart);

// control the overall size of the chart
Dimension chartDim = new Dimension(440, 440);
chartPanel.setPreferredSize(chartDim);
chartPanel.setMinimumSize(chartDim);
chartPanel.setMaximumSize(chartDim);

return chartPanel;
}

====================================================

Is there a way to control the values printed out along the x and y axis in an empty chart like this?

Thanks,

Ted Hill

josh

Re: Empty Chart

Post by josh » Wed Aug 21, 2002 2:37 pm

not sure what you mean but there is a method called getAnchorValue() that will tell you what graph point corresponds to a mouse click.

ValueAxis xAxis, yAxis;
.
.
.
.
.
chartPanel.addMouseListener()....{
mouseClicked(..){
System.out.println(xAxis.getAnchorValue()+" "+yAxis.getAnchorValue());
}
}

David Gilbert

Re: Empty Chart

Post by David Gilbert » Wed Aug 21, 2002 2:42 pm

You could manually set the range:

XYPlot plot = chart.getXYPlot();
NumberAxis xAxis = plot.getDomainAxis();
xAxis.setRange(...);

The only problem is that the range won't adjust when you do add some data to the charts.

Regards,

DG.

Ted Hill

Re: Empty Chart

Post by Ted Hill » Wed Aug 21, 2002 4:43 pm

David,

Thanks for the tip on setRange() this is just what I wanted.

Once I have valid data, I construct a completely new chart and replace the empty one.

I just want an empty 'place holder' chart on my UI to give the user some visual context before they specify the data that they want to see graphed.

Thanks a lot for a great product. It is nicely object oriented and follows the spirit of the standard Java API's very well.

Ted Hill

Locked