JFreeChart 饼图上的注释

发布于 2024-07-30 04:26:14 字数 239 浏览 9 评论 0原文

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

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

亚当

Specifically I am looking to add text annotations to specific locations to a JFreeChart that is being output to a png file for web use. Can/how do annotations get added to pie charts. I have been able to successfully add annotations to XYPlots, but don't know how to overlay or add one to a PiePlot.

My full task is to use the PiePlot to create a sort of clock. So far everything has worked great, but now I need to add labels at the 12, 3, 6, and 9 o'clock locations and completely stumped.

Adam

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

弥繁 2024-08-06 04:26:14

这是一个老问题,但这是我如何使用极坐标图做类似的事情(在 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

Bit of an old question, but here's how I did something similar (annotation at 1, 2, 3, ... o'clock positions) using a polar plot. It uses a ChoiceFormatter and the 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

winds up looking like http://img522.imageshack.us/img522/6693/hapihours.jpg

夏有森光若流苏 2024-08-06 04:26:14

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

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

将图像设置为页面背景,并在图像上设置 HTML 文本。 不好是因为它不可维护并且使数据传输令人头痛。

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

After a fairly strenuous search I don't believe this is currently possible (JFreeChart 1.0.13).
Possible options are:

Create a second chart with an XYPlot to generate a second image with needed annotations. Overlay this image on the page. This option is bad because it doubles the number of chart images to be uploaded.

Set the image as a background on the page and HTML the text over the image. Bad because it isn't maintainable and makes a headache of data transfer.

Personally I am just going to find another way to communicate the information in the title, but I wanted to post my findings for the next person.
Adam

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文