Menu

How to add "annotations" to a chart

Help
Kali
2008-12-02
2013-04-06
  • Kali

    Kali - 2008-12-02

    Hallo,

    I want to add small Annotations (Shapes, Icons, Strings,..) to a Chart2D, but couldn't figure out how to do it.
    Getting and using the Graphics context from the chart or the ChartPanel did not work.

    I need to move the annotations with the mouse, and it would be nice if they get included in the snapShot.

    Could you tell me how to achieve this best?

    Thanks in advance,

            Michael

     
    • Achim Westermann

      Hi Michael,

      I don't know if JChart2D is the right charting tool to do this. The main focus is on realtime performance. So most often it will be used for charts that move in real time. If one then would add annotations, it would a) slow down the painting and b) the annotations would run out of sync. They had to be snapped to data points.
      I recommend to search other charting libraries (e.g. JFreechart) first if they already have this feature. If not, you could post a feature request.

      kind regards,

      Achim

       
    • Bill Schoolfield

      Actually this is also something I need. I understand Achim's point of view though. My problem is I need the performance and the annotation.

      In my application, I compute, add, and remove traces based on user initiated events (from mostly sliders).

      Wouldn't it be possible to add this feature w/o killing performance? What I have in mind, is a "animation boolean". While true, these additional graphical elements would not be drawn. When false, they would appear (presumably for a  print or export operation). Think of it as an annotation layer.

      There would need to be some sort of mouse interaction to allow specification of a location (which is translated to world coordinates). The actual drawing could be done in the caller's code.  Ie. jchart2d would simply call a registered method upon the annotation boolean property change.

      There's a lot of "hand waving" here, but hopefully, you get the idea.

      In my case all I need is text annotation, everything else can be accomplished with traces.
       
      Regards,

      Bill

       
    • Kali

      Kali - 2008-12-02

      Thanks for your lightning fast reply, Achim!!

      JFreeChart has indeed annotations. But in the current version (1.0.11), the zooming function (dragging the rectangle) is unusable slow. And it is designed for static usage. I need dynamic updating and the annotations. Fortunately not both at the same time :-) But I don't want to dive into two APIs.

      I now made a small "AnnotatedChart" extending the Chart2D, and took the zooming features from ZoomingChart (rather shamelessly :-). It draws a small triangle every mouseclick, saves the position (data points) in a list and redraws the whole list when repainting. Static performance is O.K. (one trace with 35000 points, a dozen filled triangles). Only mouse click response sometimes don't work, and the chart flashes when doing the first mouseclick.

      If you want, I may post or mail it. It is just a proof of concept, but the triangles and in a next step strings are the only things I need, and so far it is promising. I will try to move the triangles with the mouse and enhance the annotations with strings in the next "version". If that is still fast enough, I will think about an annotation layer.

      Regards,

             Michael

       
    • Achim Westermann

      @Bill

      yes this could be a way: the annotation feature could be controlled by a boolean flag. So everyone that enables it will have to deal with the slower performance. Others would pay just the check for the flag per paint operation (not more than 20 operations per second). One of JChart2D's user for example uses several charts for real time race car telemetry and could not afford to have this feature running all the time.
      You could add a feature request.

      @kali
      I would be interested to get an inspiration. I hope you did this by subclassing (vs. modifying the Chart2D class).

      @both

      I think it would not be good to have annotations fixed to a position. This would be fuzzy when the chart is running over time. Is it the case that those annotations should be related to a data point? In that case it would be best to have the annotations linked to the data points data model. In the new version 3.1.0 there are already routines to find the nearest point to the current mouse position (which would allow to add the annotation to the point).

      kind regards,

      Achim

       
      • Bill Schoolfield

        I will formally make this request. I don't understand what you mean when you say "This would be fuzzy when the chart is running over time". Please advise.

        My strong preference is for annotations to not be associated with a trace (or at least have the option to be). The real world coordinates would mark the position so if the chart is resized the graphics would move accordingly.

        Bill

         
    • Bill Schoolfield

      As a follow up, I suppose it would be ok to use a pseudo trace that's optionally hidden and tie the annotation to a point in the trace. This might make the coding easier and more consistent with what you have already.

      Bill

       

Anonymous
Anonymous

Add attachments
Cancel





MongoDB Logo MongoDB