LineChart - how to set max Y axis value

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

LineChart - how to set max Y axis value

Post by jim » Tue Apr 16, 2002 1:25 pm

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());
}

David Gilbert

Re: LineChart - how to set max Y axis value

Post by David Gilbert » Tue Apr 16, 2002 3:03 pm

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.

charlotte

Re: LineChart - how to set max Y axis value

Post by charlotte » Tue Apr 16, 2002 5:44 pm

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.

Locked