1

I want to display the X values on to the XY line chart As shown below: How can i do this? enter image description here I want to display it like this: enter image description here 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);
  }
}
Parth Soni
  • 11,158
  • 4
  • 32
  • 54
  • What's your actual problem? You have a series of data points which ALL have the same height and so you have got a straight line. I can't see anything obviously wrong. – peter.murray.rust Apr 26 '12 at 06:56
  • @peter.murray.rust: the problem is i want to display the data above this line as shown [here](http://i.stack.imgur.com/zNRuE.png). How can i do this? – Parth Soni Apr 26 '12 at 07:03

1 Answers1

2

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

enter image description here

Community
  • 1
  • 1
trashgod
  • 203,806
  • 29
  • 246
  • 1,045
  • i've not much familiar with this... i've tried [this](http://pastebin.com/siU9Q92p), but why its not working? – Parth Soni Apr 26 '12 at 12:06
  • Thanks man... :) Is there any other way so i can display this graph with my another `XYAreaChart`? – Parth Soni Apr 26 '12 at 12:41
  • You could look at a [`Combined*Plot`](http://www.jfree.org/jfreechart/api/javadoc/org/jfree/chart/plot/package-summary.html) or [separate panels](http://stackoverflow.com/a/7602126/230513). – trashgod Apr 26 '12 at 12:48