Reputation: 11648
I want to display the X values on to the XY line chart As shown below: How can i do this? I want to display it like this: Here's my code to display the line Graph:
public class LineChartDemo6{
public static void main(String arg[]){
XYSeries series = new XYSeries("Average Weight");
series.add(20.0, 20.0);
series.add(40.0, 20.0);
series.add(55.0, 20.0);
series.add(70.0, 20.0);
XYDataset xyDataset = new XYSeriesCollection(series);
JFreeChart chart = ChartFactory.createXYLineChart
("XYLine Chart using JFreeChart", "Age", "Weight",
xyDataset, PlotOrientation.VERTICAL, true, true, false);
ChartFrame frame1=new ChartFrame("XYLine Chart",chart);
frame1.setVisible(true);
frame1.setSize(300,300);
}
}
Upvotes: 1
Views: 592
Reputation: 205785
You can add an XYItemLabelGenerator
to your plot's renderer, as shown in this example and this example. It looks like ArgumentIndex {1}
is the domain value.
Addendum: Your example works fine; it just needs a little extra margin.
ValueAxis range = plot.getRangeAxis();
range.setUpperMargin(0.20);
Upvotes: 2