Is there a way to set the Y axis max value? The chart that I am generating is a linechart that shows the cpu utilization. The Y-axis is the percentage utilized, but most of the time it is only around 20, I want the Y axis to show 100.
I am using jfreechart in a servlet ... below is a snipit of my code.
THanks
Jim
jschimmoeller@tdms-lives.com
JFreeChart chart = null;
try {
CategoryDataset ds = this.getData(hostname, graphInterval);
chart = ChartFactory.createLineChart("CPU Utilization for
Host: "+hostname, xTitle, "Percentage Utilized", ds, true);
chart.setBackgroundPaint(new GradientPaint(0, 0, Color.white,
1000, 0, Color.white));
OutputStream out = response.getOutputStream();
ChartUtilities.writeChartAsPNG(out, chart, width, height);
out.close();
} catch (Exception e) {
throw new ServletException( e.toString());
}
LineChart - how to set max Y axis value
Re: LineChart - how to set max Y axis value
jim wrote:
> Is there a way to set the Y axis max value? The chart that I
> am generating is a linechart that shows the cpu utilization.
> The Y-axis is the percentage utilized, but most of the time
> it is only around 20, I want the Y axis to show 100.
This will do it for you:
XYPlot plot = chart.getXYPlot();
NumberAxis rangeAxis = (NumberAxis)plot.getRangeAxis();
rangeAxis.setAxisRange(0.0, 100.0);
// or rangeAxis.setMaximumAxisValue(100.0);
Regards,
DG.
> Is there a way to set the Y axis max value? The chart that I
> am generating is a linechart that shows the cpu utilization.
> The Y-axis is the percentage utilized, but most of the time
> it is only around 20, I want the Y axis to show 100.
This will do it for you:
XYPlot plot = chart.getXYPlot();
NumberAxis rangeAxis = (NumberAxis)plot.getRangeAxis();
rangeAxis.setAxisRange(0.0, 100.0);
// or rangeAxis.setMaximumAxisValue(100.0);
Regards,
DG.
Re: LineChart - how to set max Y axis value
hi,
i'd like to do the same, but with a VerticalBarChart, and the methods getXYPlot() and getRangeAxis() don't exist... i want to change the values of the YAxis, because it is:
1
0.9
0.8
0.7
....
0.1
and i want only
1
0
thanks for help,
Charlotte.
i'd like to do the same, but with a VerticalBarChart, and the methods getXYPlot() and getRangeAxis() don't exist... i want to change the values of the YAxis, because it is:
1
0.9
0.8
0.7
....
0.1
and i want only
1
0
thanks for help,
Charlotte.