我有一组包含2组图形(检测和本地化)的图形。第一组(本地化)是红色,橙色,粉红色,第二组(检测)是蓝色,黑色,青色。我为每个集创建了一个渲染器以设置颜色。我已将工具提示设置为true,但当我将鼠标移到第二组(检测)时,我看不到标签。我只能在鼠标悬停时看到第一组标签(见图片),但不能看到另一套标签。这是我的代码:
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),但它给出了一个非常例外。
答案 0 :(得分:1)
XYToolTipGenerator
为renderer1
时, ChartFactory.createTimeSeriesChart()
会为tooltips
添加true
。您可能只需要将其与renderer2
:
renderer2.setBaseToolTipGenerator(renderer1.getBaseToolTipGenerator());
或者您可以向renderer2
添加新的
XYToolTipGenerator toolTipGenerator2 = StandardXYToolTipGenerator.getTimeSeriesInstance();
renderer2.setBaseToolTipGenerator(toolTipGenerator2);