代码之家  ›  专栏  ›  技术社区  ›  Adam

JFreeChart饼图上的注释

  •  0
  • Adam  · 技术社区  · 15 年前

    具体来说,我希望将文本注释添加到jfreechart的特定位置,该jfreechart将输出到PNG文件供Web使用。如何将注释添加到饼图中?我已经成功地向xyplots添加了注释,但不知道如何覆盖或向pieplot添加注释。

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

    亚当

    2 回复  |  直到 13 年前
        1
  •  2
  •   schnee    13 年前

    这是一个古老的问题,但我是如何做类似的事情的(注释在1,2,3,……使用极坐标图。它使用一个选项格式和数字勾号单位:

        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

        2
  •  0
  •   Adam    15 年前

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

    用xyplot创建第二个图表,以生成带有所需注释的第二个图像。在页面上覆盖此图像。此选项不好,因为它使要上载的图表图像数加倍。

    将图像设置为页面上的背景,并将文本以HTML格式覆盖图像。不好,因为它不可维护,而且数据传输很麻烦。

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