2013-05-03 84 views
2

我正在使用JFreeChart,我想只有一个维度的图表: 一个x轴(表示毫秒)和形状(表示事件)。JFreeChart:一轴分布图

我创建了一个XYLineChart和具有隐藏y轴的XYPlot:

this.chart = ChartFactory.createXYLineChart(
    "","","",dataset,PlotOrientation.VERTICAL, false, true,false); 

XYPlot plot = (XYPlot) chart.getPlot(); 

plot.setBackgroundPaint(Color.lightGray); 
plot.setDomainGridlinePaint(Color.white); 
plot.setRangeGridlinePaint(Color.white); 
plot.setRangeGridlinesVisible(false); 
plot.setDomainCrosshairVisible(true); 
plot.setRangeCrosshairVisible(false); 

NumberAxis range = (NumberAxis) plot.getRangeAxis(); 
range.setVisible(false); 
range.setRange(0.0, 1.0); 
range.setTickUnit(new NumberTickUnit(0.5)); 

在我使用的固定y坐标的数据集。

我得到这个结果:

image 1 http://imageshack.us/a/img46/4935/pointsuw.jpg

,但我想有这样的事情:

image 2 http://img521.imageshack.us/img521/3721/points2.jpg

如果我只是调整面板,整个图表的大小(标题,数字,形状)。 所以我想只调整“灰色区域”。

显然,如果存在另一个适当的图表类型,则会更好。

非常感谢。

+0

请编辑您的问题包括[SSCCE(http://sscce.org/)所示的方法之一,它实现[这里](http://stackoverflow.com/a/10277372/230513 )。 – trashgod 2013-05-03 02:08:55

回答

0

如果整个图表的宽度/高度低于可配置的阈值,则会调整其大小。

我已经修改了您的示例,方法是添加ChartPanel的代码并使用ChartPanel.setMinimumDrawWidth(int)ChartPanel.setMinimumDrawWidth(int)这两种方法设置这些阈值。

this.chart = ChartFactory.createXYLineChart(
"","","",dataset,PlotOrientation.VERTICAL, false, true,false); 

XYPlot plot = (XYPlot) chart.getPlot(); 

plot.setBackgroundPaint(Color.lightGray); 
plot.setDomainGridlinePaint(Color.white); 
plot.setRangeGridlinePaint(Color.white); 
plot.setRangeGridlinesVisible(false); 
plot.setDomainCrosshairVisible(true); 
plot.setRangeCrosshairVisible(false); 

NumberAxis range = (NumberAxis) plot.getRangeAxis(); 
range.setVisible(false); 
range.setRange(0.0, 1.0); 
range.setTickUnit(new NumberTickUnit(0.5)); 

ChartPanel chartPanel = new ChartPanel(this.chart); 
chart.setMinimumDrawHeight(10); 
chart.setMinimumDrawWidth(10); 
+0

这是否回答你的问题?在这种情况下,请将您的问题标记为已解决。谢谢! – Uli 2015-02-04 08:42:54