Customize the x-axis labels

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

Customize the x-axis labels

Post by guest » Fri Nov 21, 2003 4:13 pm

I am new to java and jfreechart. I have created a line chart. My x-axis has values (1, 2, 3,4,5,6,7,8,9,10,11,12,13,14). But I would like to have the following values displayed as labels(please note: some values should be blank):
3M,6M,1Y, ,2Y, ,5y, , ,10y, , , ,30Y

Which class I should use to get this result? any sample code? Here is my code. Thanks for help!

YieldXYDataset dataset = new YieldXYDataset();
dataset.loadData();

JFreeChart chart = ChartFactory.createXYLineChart
(seriesNames, // Title
"Time Period", // X-Axis label
"Yield", // Y-Axis label
dataset, // Dataset
PlotOrientation.VERTICAL,// Orientation
true, // Show legend
true, // Show tooltips
false // generate URLs
);

// format the Y-Axis label to use %
XYPlot plot = chart.getXYPlot();
NumberAxis yAxis = (NumberAxis) plot.getRangeAxis();
yAxis.setNumberFormatOverride(new DecimalFormat("##.###%"));
yAxis.setAutoRangeIncludesZero(false);

// Write the chart image to the temporary directory
ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection());
filename = ServletUtilities.saveChartAsPNG(chart, 500, 300, info, session);

// Write the image map to the PrintWriter
ChartUtilities.writeImageMap(pw, filename, info);
pw.flush();

guest

Customize the x-axis labels

Post by guest » Mon Nov 24, 2003 4:45 pm

can someone please help me with this request? Thanks a lot in advance.

Matthias
Posts: 42
Joined: Fri Apr 18, 2003 9:49 am
Location: Germany

Post by Matthias » Tue Nov 25, 2003 2:42 pm

Maybe you can use the SymbilcAxis class for this. Look at the corresponding demos in the standard distribution (e.g. XYTickLabelDemo). In Release 0.9.14 this class is buggy; you can use the CVS version or apply the patch for refreshTicks() provided here: http://www.jfree.org/phpBB2/viewtopic.php?t=6307 .

Locked