2012-06-26 26 views
0

我正在使用jfreechart庫繪製系列圖。我已經取得了y軸上的值,x軸上的時間和3個系列的值。一切都很好,但我無法放大域軸,雖然它的範圍軸的罰款。任何人都可以告訴我,如果有可能,如果是的話,請幫助代碼。JFreeChart:當使用CategoryAxis時,域軸放大功能不起作用

下面的代碼行可以幫你找到我的代碼一些場景

final ChartPanel chartPanel = new ChartPanel(chart); 
chartPanel.setDomainZoomable(true); 
chartPanel.setRangeZoomable(true); 
this.add(chartPanel, BorderLayout.CENTER); 

//set plot specifications 
final CategoryPlot plot = (CategoryPlot) chart.getPlot(); 
plot.setBackgroundPaint(new Color(0xffffe0)); 
plot.setDomainGridlinesVisible(true); 
plot.setDomainGridlinePaint(Color.lightGray); 
plot.setRangeGridlinePaint(Color.lightGray); 

//CUSTOMIZE DOMAIN AXIS 
final CategoryAxis domainAxis = (CategoryAxis) plot.getDomainAxis(); 

//customize domain label position 
domainAxis.setCategoryLabelPositions(
     CategoryLabelPositions.createUpRotationLabelPositions(Math.PI/6.0) 
); 

回答

1

它看起來像你使用的是CategoryPlot不支持zooing在域範圍

enter image description here

要允許變焦時,如果您使用的是圖表工廠代碼

JFreeChart chart = ChartFactory.createXYLineChart(...); 

如果你能劇情強制轉換爲CategoryPlot了毛病在域軸切換到XYPlot。我檢查了LineChartDemo3並且此代碼導致錯誤(java.lang.ClassCastException):

try { 
     final CategoryPlot cplot = (CategoryPlot) chart.getPlot(); 
    } catch (Exception e) { 
     e.printStackTrace(); 
    } 
+0

Thanks @GrahmaA。如果我可以使用除CategoryPlot以外的任何其他類別來將類別顯示爲具有域放大選項的系列? – dirtyhandsphp

+0

@dirtyhandsphp如果你可以用[SSCCE](http://sscce.org/)更新你的帖子或者指向[JFreeChart Demo](http://www.jfree.org/jfreechart)的方向/jfreechart-1.0.13-demo.jnlp)顯示我將進一步調查的問題。在JFreeChart演示LineChartDemo3顯示與類別的'XYPlot'這是一個合適的解決方案? – GrahamA

+0

我的圖形和LineChartDemo3唯一的區別是我在域軸上使用時間而不是數值。 – dirtyhandsphp