2017-07-17 68 views
1

enter image description here我有一個包含2組圖形(檢測和本地化)的圖形。第一組(本地化)是紅色,橙色,粉紅色和第二組(檢測)是藍色,黑色,青色。我爲每個集合創建了一個渲染器來設置顏色。我已經將工具提示設置爲true,但是當我在第二組(檢測)上進行鼠標懸停時,我看不到標籤。我可以在鼠標懸停時查看標籤(僅供參考),但不能用於其他設置。這裏是我的代碼:jfreechart多個渲染器工具提示不工作

JFreeChart avg_chart = ChartFactory.createTimeSeriesChart(
      "Average detections and localizations" , 
      "" , 
      "" , 
      null , 
      true , true , false); 
    avg_chart.setBackgroundPaint(Color.WHITE); 

    final XYPlot plot = avg_chart.getXYPlot(); 
    plot.setDataset(0,this.dataset_local); 
    plot.setDataset(1,this.dataset_detect); 
    plot.setRangeAxis(0,new NumberAxis("Localizations")); 
    plot.setRangeAxis(1,new NumberAxis("Detections")); 

    plot.mapDatasetToRangeAxis(0, 0); 
    plot.mapDatasetToRangeAxis(1, 1); 

    plot.setDomainCrosshairVisible(true); 
    plot.setRangeCrosshairVisible(true); 

    XYLineAndShapeRenderer renderer1 = (XYLineAndShapeRenderer) plot.getRenderer(0);//localization 
    renderer1.setSeriesPaint(0 , Color.RED); 
    renderer1.setSeriesPaint(1 , Color.MAGENTA); 
    renderer1.setSeriesPaint(2 , Color.orange); 
    renderer1.setBaseItemLabelsVisible(true); 

    XYLineAndShapeRenderer renderer2 = new XYLineAndShapeRenderer(true, false); //detection **************** 
    renderer2.setSeriesPaint(0 , Color.BLUE); 
    renderer2.setSeriesPaint(1 , Color.BLACK); 
    renderer2.setSeriesPaint(2 , Color.CYAN); 
    renderer2.setBaseItemLabelsVisible(true); 

    plot.setRenderer(0,renderer1); 
    plot.setRenderer(1,renderer2); 

    plot.setBackgroundPaint(Color.lightGray); 
    plot.setDomainGridlinePaint(Color.white); 
    plot.setRangeGridlinePaint(Color.white); 
    DateAxis axis = (DateAxis) plot.getDomainAxis(); 
    axis.setDateFormatOverride(new SimpleDateFormat("dd/MM/yyyy")); 
    return avg_chart; 

} 

我已經試過XYLineAndShapeRenderer renderer2 =(XYLineAndShapeRenderer)plot.getRenderer(1),但它給是nulll例外。

回答

1

ChartFactory.createTimeSeriesChart()tooltipstrue增加了XYToolTipGeneratorrenderer1。你可能只需要與renderer2使用它:

renderer2.setBaseToolTipGenerator(renderer1.getBaseToolTipGenerator()); 

或者你也可以添加一個新來renderer2

XYToolTipGenerator toolTipGenerator2 = StandardXYToolTipGenerator.getTimeSeriesInstance(); 
renderer2.setBaseToolTipGenerator(toolTipGenerator2);