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
Empty Chart
Re: Empty Chart
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());
}
}
ValueAxis xAxis, yAxis;
.
.
.
.
.
chartPanel.addMouseListener()....{
mouseClicked(..){
System.out.println(xAxis.getAnchorValue()+" "+yAxis.getAnchorValue());
}
}
Re: Empty Chart
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.
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.
Re: Empty Chart
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
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