【问题标题】:Annotations on a JFreeChart Pie ChartJFreeChart 饼图上的注释
【发布时间】:2009-07-29 17:13:45
【问题描述】:

具体来说,我希望将文本注释添加到 JFreeChart 的特定位置,该 JFreeChart 正在输出到 png 文件以供 Web 使用。可以/如何将注释添加到饼图中。我已经能够成功地将注释添加到 XYPlot,但不知道如何覆盖或添加到 PiePlot。

我的全部任务是使用 PiePlot 创建一种时钟。到目前为止,一切都很好,但现在我需要在 12、3、6 和 9 点位置添加标签,并且完全被难住了。

亚当

【问题讨论】:

    标签: annotations jfreechart pie-chart


    【解决方案1】:

    有点老问题,但这是我如何使用极坐标图做类似的事情(在 1、2、3、... 点钟位置进行注释)。它使用 ChoiceFormatter 和 NumberTickUnit:

        final JFreeChart chart = ChartFactory.createPolarChart(
                "HAPI Hourly Usage (UTC)", ds, true, true, false);
        final PolarPlot plot = (PolarPlot) chart.getPlot();
    
        // Create a ChoiceFormat to map the degrees to clock positions
        double[] limits = new double[12];
        String[] formats = new String[12];
        limits[0] = 0;
        formats[0] = "12";
    
        // degrees = 360/12
        for (int i = 1; i < limits.length; i++) {
            limits[i] = degrees * (i);
            formats[i] = Integer.toString(i);
        }
        ChoiceFormat clock = new ChoiceFormat(limits, formats);
    
        TickUnit tickUnit = new NumberTickUnit(degrees, clock);
    
        // now configure the plot
        plot.setAngleTickUnit(tickUnit); // sets the ticks
        plot.setAngleLabelsVisible(true); // makes the labels visible
        plot.setAngleLabelPaint(Color.LIGHT_GRAY); // user choice
        plot.setAngleGridlinesVisible(true); // must set this to display the
                                             // labels
        plot.setAngleGridlinePaint(Color.BLACK); // plot's background color
                                                 // (makes lines invisible)
        plot.setRadiusGridlinesVisible(false); //turn off the radius value circles
        ValueAxis axis = plot.getAxis();
        axis.setTickLabelsVisible(false); //turn off the radius value labels
    

    看起来像http://img522.imageshack.us/img522/6693/hapihours.jpg

    【讨论】:

    • 有趣的技巧!因此,您基本上会使用极坐标图来制作饼图式的 qraph。这为您购买了刻度单位和标签的使用?很酷。
    • 顺便说一句,对于那些尚未寻找答案的人来说,这是一个老问题并不重要。感谢您的帮助!
    【解决方案2】:

    经过相当艰苦的搜索后,我认为这目前是不可能的(JFreeChart 1.0.13)。 可能的选项是:

    使用 XYPlot 创建第二个图表,以生成带有所需注释的第二个图像。在页面上叠加此图像。此选项不好,因为它会使要上传的图表图像数量翻倍。

    将图像设置为页面背景,并在图像上添加 HTML 文本。不好,因为它不可维护并且让数据传输很头疼。

    就我个人而言,我只是想找到另一种方式来传达标题中的信息,但我想将我的发现发布给下一个人。 亚当

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-04-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多