How can I modify the Y-Axis so that the values which appear there do not show any decimal precision?
Here is the code for a JSP that generates LineChart jpeg:
<%@ page import = "
java.io.*,
java.awt.*,
com.odesys.chart.*,
com.odesys.chart.image.*,
com.odesys.chart.linechart.*"
contentType="image/jpeg"%><%
// Create and initialize a LineChartImage instance
LineChartImage chart = new LineChartImage();
chart.setSize(400, 300);
chart.setBackground(Color.white);
chart.setFont(new Font("Helvetica", Font.ITALIC, 12));
chart.setLegendVisible(true);
chart.setQuality(0.9f);
chart.setDrawVertLines(true);
chart.getAxisX().setName("x");
chart.getAxisY().setName("y");
// Set the data into the model
DefaultLineChartModel model = (DefaultLineChartModel)chart.getModel();
model.setUpdateLocked(true);
PointData data;
DefaultLine line = (DefaultLine)model.addSeries();
line.setStyle(Line.NONE);
line.setLabel("Series Name");
for(float x = 0.0f; x <= 10.0f; x += 0.5f)
{
data = (PointData)line.addElement();
data.setX(x);
data.setY(x*x);
}
// Unlock the update to allow the chart to recalculate its internal state
// to make sure the axis marks have correct values.
model.setUpdateLocked(false);
// Get the Axis object that represents the Y-axis
Axis axisY = chart.getAxisY();
// Make sure the axis marks are not recalculated automatically anymore
axisY.setMarksAuto(false);
// Create a new array of AxisMark objects with the same values as the current one,
// but with labels that are formated according to your preferences.
AxisMark[] oldMarks = axisY.getMarks();
AxisMark[] newMarks = new AxisMark[oldMarks.length];
for(int i = 0; i < oldMarks.length; i++)
{
int value = (int)oldMarks[i].getValue(); // use an integer to avoid the decimal precision.
newMarks[i] = new AxisMark(oldMarks[i].getValue(), String.valueOf(value));
}
// Set the new marks to the Y-axis
axisY.setMarks(newMarks);
// Write the image into a byte array
ByteArrayOutputStream baos = new ByteArrayOutputStream();
chart.write(baos);
// Write the image back to the client
response.setContentLength(baos.size());
OutputStream os = response.getOutputStream();
baos.writeTo(os);
%>