2

我正在尝试将 aStandardXYItemLabelGeneratorXYAreaRenderer2渲染器一起使用,但没有显示任何内容。如果使用相同的代码,XYLineAndShapeRenderer我可以正确地看到图表上的标签。我怎样才能看到这些标签XYAreaChart

 // create the chart...
        final JFreeChart chart = ChartFactory.createXYAreaChart(
                header_label, // chart title
                x_label, // x axis label
                y_label, // y axis lsabel
                dataset, // data
                PlotOrientation.VERTICAL,
                includeLegend, // include legend
                true, // tooltips
                false // urls
                );

        // NOW DO SOME OPTIONAL CUSTOMIZATION OF THE CHART...
        chart.setBackgroundPaint(Color.white);

        // get a reference to the plot for further customization...
        final XYPlot plot = chart.getXYPlot();
        plot.setBackgroundPaint(Color.lightGray);
        plot.setDomainGridlinePaint(Color.white); // X Axis is Domain
        plot.setRangeGridlinePaint(Color.white);  // Y Axis is Range

        // Allow lines and shapes to be visible
        renderer1 = new XYAreaRenderer();

        // Set the tooltip generator
        renderer1.setBaseToolTipGenerator(toolTipGenerator);

        NumberFormat.getNumberInstance().setMaximumFractionDigits(2);
//        renderer1.setBaseItemLabelGenerator(new StandardXYItemLabelGenerator("{0} {1} {2}", NumberFormat.getNumberInstance(), NumberFormat.getNumberInstance()));
        renderer1.setBaseItemLabelGenerator(new StandardXYItemLabelGenerator("test  {0} {1} {2}", NumberFormat.getNumberInstance(), NumberFormat.getNumberInstance()));

        renderer1.setBaseItemLabelsVisible(true);

        plot.setRenderer(renderer1);
4

1 回答 1

3

与 不同XYLineAndShapeRenderer,既不XYAreaRenderer也不XYAreaRenderer2调用抽象父级的drawItemLabel(). 实际上,标签不受支持,但工具提示支持,如下所示。

XYAreaRenderer2 renderer = new XYAreaRenderer2(
    new StandardXYToolTipGenerator("test: {0} {1} {2}",
    NumberFormat.getNumberInstance(),
    NumberFormat.getNumberInstance()), null);
plot.setRenderer(renderer);
于 2012-07-13T23:41:06.047 回答