我创建了一个双Y轴的条形图。
Dataset[] dataset = ChartsBuilder.createChartDatasets(chartModelType);
JFreeChart chart = ChartFactory.createBarChart(chartModelType.getChartName(), // chart title
chartModelType.getDomainAxisLabel(), // domain axis label
chartModelType.getRangeAxisLabel(), // range axis label
(CategoryDataset)dataset[0], // data
chartModelType.getPlotOrientation(), // orientation
true, // include legend
true, // tooltips?
false // URLs?
);
// set the background color for the chart...
chart.setBackgroundPaint(Color.white);
// get a reference to the plot for further customisation...
CategoryPlot plot = (CategoryPlot)chart.getPlot();
// set the range axis to display integers only...
NumberAxis rangeAxis = (NumberAxis)plot.getRangeAxis();
rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
// // disable bar outlines...
// if (reportChart.getRenderer() != null) {
// plot.setRenderer((CategoryItemRenderer)reportChart.getRenderer());
// }
// ((CategoryPlot)chart.getPlot()).setRenderer(new BarRenderer3D());
BarRenderer renderer = (BarRenderer)plot.getRenderer();
renderer.setDrawBarOutline(true);
renderer.setMaximumBarWidth(.05);
// set up gradient paints for series...
GradientPaint gp0 = new GradientPaint(0.0f, 0.0f, Color.blue, 0.0f, 0.0f, new Color(0, 0, 64));
renderer.setSeriesPaint(0, gp0);
CategoryAxis domainAxis = plot.getDomainAxis();
domainAxis.setCategoryMargin(0.1f);
// domainAxis.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(Math.PI
// / 6.0));
if (dataset[1] != null) {
final NumberAxis axis2 = new NumberAxis(chartModelType.getSecondRangeAxisLabel());
plot.setDataset(1, (CategoryDataset)dataset[1]);
plot.mapDatasetToRangeAxis(1, 1);
plot.setRangeAxis(1, axis2);
plot.setRangeAxisLocation(1, AxisLocation.BOTTOM_OR_RIGHT);
final BarRenderer renderer2 = new BarRenderer();
renderer2.setDrawBarOutline(true);
renderer2.setMaximumBarWidth(.05);
plot.setRenderer(1, renderer2);
}
return chart;
因此我的图表上有2层图像,如果我尝试从renderer2获取Hint,那么我会从第一个渲染器的最近的条形图中得到提示。
其实我有两个问题:
是否可以在1个渲染器中设置两个数据集,但可以根据自己的Y轴进行缩放;
如果我不可能,我怎么能为每个渲染器自定义提示点(直接看到我想要的东西)。