在XYLineChart上显示X值

时间:2012-04-26 06:30:21

标签: java swing jfreechart

我想在XY折线图上显示X值如下图所示: 我怎样才能做到这一点? enter image description here 我想这样显示: enter image description here 这是我的代码,用于显示图表行:

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

1 个答案:

答案 0 :(得分:2)

您可以向地块的渲染器添加XYItemLabelGenerator,如此example和此example所示。看起来 ArgumentIndex {1}是域值。

附录:您的example工作正常;它只需要一点额外的保证金

ValueAxis range = plot.getRangeAxis();
range.setUpperMargin(0.20);

enter image description here