2013-05-03 72 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