jfree chart draw image on a category plot

隐身守侯 提交于 2019-12-12 03:45:14

问题


Heyy folks I have a pretty strange requirement.I need to draw an arrow shaped image beside a stacked bar chart in a category plot .The arrow image has to be red or green depending on some pre defined condition.I just need help to find a method to draw an image outside the stacked bar on the plot using jfree chart.Please help me out with this guys .Being stuck with this for days !!!!


回答1:


You could implement the CategoryAnnotation interface:

plot.addAnnotation(new CategoryAnnotation(){

   Image anImage = ImageIO.read(new File("anImage.jpg"));

   @Override
   public void draw(Graphics2D g2, CategoryPlot plot, Rectangle2D dataArea, CategoryAxis domainAxis, ValueAxis rangeAxis){

       int x = ...  // determine where you want to draw the image inside the dataArea rectangle
       int y = ...

       g2.drawImage(anImage, x, y, null);

   }
});



回答2:


Do you need an arrow, an image or an image cropped to an arrow? In the first case, I would look at CategoryPointerAnnotation. In the second case, look at the source of XYImageAnnotation and wrap the logic in a custom CategoryAnnotation. An XYImageAnnotation itself won´t work, if your plot is indeed a CategoryPlot.



来源:https://stackoverflow.com/questions/31912323/jfree-chart-draw-image-on-a-category-plot

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!