2015-10-18 62 views
0

我创建的JFreeChart是一个LineChart。我遇到的问题是图表上的行未显示。Line在Netbeans IDE的LineChart上不显示

谁能告诉我为什么发生这种情况。

这里是按钮的代码:

DefaultCategoryDataset dataset2 = new DefaultCategoryDataset(); 
     dataset2.setValue(100, "John B","EMP0001"); 
     dataset2.setValue(200, "John A","EMP0003"); 

     JFreeChart chart2 = ChartFactory.createLineChart("Comission", "Employee", "Number of Sales", dataset2, PlotOrientation.VERTICAL, false, true, true); 
     chart2.setBackgroundPaint(Color.YELLOW); 
     chart2.getTitle().setPaint(Color.RED); 
     CategoryPlot p2 = chart2.getCategoryPlot(); 
     p2.setRangeGridlinePaint(Color.BLUE); 
     ChartFrame frame2 = new ChartFrame("Employee Comission", chart2); 
     frame2.setVisible(true); 
     frame2.setSize(450,350); 

这是创建折线图时会发生什么:

Line chart without line displaying on chart

请会有人帮助刚刚指示我哪里可能问题在于。

回答

0

为了显示一行,您需要有两个数据项具有相同的rowKey值和不同的列值键值。

,如果你的数据更改为:

dataset2.setValue(100, "John A","EMP0000"); 
dataset2.setValue(200, "John A","EMP0001"); 
dataset2.setValue(300, "John B","EMP0002"); 
dataset2.setValue(400, "John B","EMP0004"); 

然后在图:

plot with two values

注意到, “约翰·A” 的值是红色, “约翰·B” 的值是蓝色的和 红色和蓝色不连接。列值沿底部打印。