How to add markings inside a PlotClickListener

38 views
Skip to first unread message

Shahriar Haque

unread,
Jul 9, 2013, 7:02:36 PM7/9/13
to gf...@googlegroups.com
I would like to create a vertical marking whenever the user clicks inside the plot.

This is what I have tried so far without any success:

  • Create an empty Markings object
  • Added the Markings object to the GridOptions
  • Inside a plot click listener:
    • I create a new marking with the current x axis position
    • Add the marking to the Markings object
    • I call the redraw method on the simpleplot

Does anybody have any pointers on what I am doing wrong?


GflotDemo.java

Nicolas Morel

unread,
Jul 10, 2013, 4:14:44 PM7/10/13
to gf...@googlegroups.com
Hi, 

The problem is that you add your marking to the wrong Markings. When the plot is really created by flot (when placeholder added to the DOM), the options are duplicated and you have to modify this duplicate. 
The reference to the Markings object you are keeping isn't used by flot. 

To get the correct options, you have to retrieve them with plot.getPlotOptions() after the plot have been created. So you can initialize the Markings option and then in your click listener do :
plot1.getPlotOptions().getGridOptions().getMarkings().addMarking(m);

You can also initialize your markingsArray with the above code and keep your current click listener :
plot1.addLoadHandler( new PlotLoadEvent.Handler() {
    @Override
    public void onLoad( PlotLoadEvent event )
    {
       markingsArray = plot1.getPlotOptions().getGridOptions().getMarkings();
    }
} );
Reply all
Reply to author
Forward
0 new messages