2009-07-29 86 views
0

具体而言,我正在寻找将文本注释添加到特定位置的JFreeChart,该JFreeChart被输出到可供web使用的png文件中。可以/如何将注释添加到饼图中。我已经能够成功地将注释添加到XYPlot,但不知道如何覆盖或添加一个PiePlot。JFreeChart饼图上的注释

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

亚当

回答

0

一个相当艰苦的搜索后,我不相信这是目前可能(JFreeChart的1.0.13)。 可能的选项有:

用XYPlot创建第二个图表以生成需要注释的第二个图像。在页面上覆盖此图像。此选项很糟糕,因为它会使要上传的图表图像数量增加一倍。

将图像设置为页面上的背景,并将图像上的文字设置为HTML。不好,因为它不可维护,让数据传输变得头痛。

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

2

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

+0

有趣的技术!所以你基本上会用一个极地情节来制作一个饼图式的qraph。这会让你使用刻度单位和标签?很酷。 – Adam 2011-12-21 22:26:30

+0

对于那些还没有寻找答案的人来说,这并不重要,这是一个老问题。谢谢您的帮助! – Adam 2011-12-21 22:27:19