jfree chart draw image on a category plot

2019-09-16 12:35发布

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 !!!!

2条回答
手持菜刀,她持情操
2楼-- · 2019-09-16 13:05

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.

查看更多
Juvenile、少年°
3楼-- · 2019-09-16 13:15

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);

   }
});
查看更多
登录 后发表回答