2012-04-26 58 views
1

我想在XY折线图上显示X值如下图所示: 我该怎么做? enter image description here 我想是这样显示的: enter image description here 这里是我的代码,以显示折线图:在XYLineChart上显示X值

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

什么是你的实际问题?你有一系列的数据点都有相同的高度,所以你有一条直线。我看不出有什么明显的错误。 – 2012-04-26 06:56:11

+0

@ peter.murray.rust:问题是我想显示这行上面的数据,如[这里](http://i.stack.imgur.com/zNRuE.png)所示。我怎样才能做到这一点? – Parth 2012-04-26 07:03:35

回答

2

您可以添加XYItemLabelGenerator您情节的渲染器,如本exampleexample 。它看起来像参数索引{1}是域值。

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

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

enter image description here

+0

我对此没有太多的了解...我试过[this](http://pastebin.com/siU9Q92p),但为什么它不工作? – Parth 2012-04-26 12:06:46

+0

谢谢... :)有没有其他的方式,所以我可以用我的另一个'XYAreaChart'显示这个图? – Parth 2012-04-26 12:41:01

+0

您可以查看['Combined * Plot'](http://www.jfree.org/jfreechart/api/javadoc/org/jfree/chart/plot/package-summary.html)或[单独的面板]( http://stackoverflow.com/a/7602126/230513)。 – trashgod 2012-04-26 12:48:07