Primefaces 5.2 get jqplot instance from p:chart

1.3k views Asked by At

I have p:chart on my site like this

<p:chart id="chart" type="line" widgetVar="chart" model="#{resultsViewController.areaModel}" style="height:600px"/>

Now I want the client to be able to modify some display options without reloading the page, in order to do that I need to acquire the jqplot instance. How can I do that?

I read that you can do it like this: http://forum.primefaces.org/viewtopic.php?f=3&t=24667

But using it like this

 $('#chart').data('jqplot').plot.replot( { resetAxes: true } );

yields no data() function

P.S I am aware of the possibility to extend Primefaces renderer for charts but this is not an option for me.

1

There are 1 answers

0
CodeSamurai777 On BEST ANSWER

Ok so I found the answer thanks to useful link on PF client side API:

http://blog.hatemalimam.com/intro-to-primefaces-widgetvar/

So the short answer is, you need to assagin a widgetVar atrribute and then using PrimeFaces object get instance of jqplot like this:

 <p:chart id="chart" type="line" widgetVar="chart" model="#{resultsViewController.areaModel}" style="height:600px"/>

Like this:

var jqplot = PrimeFaces.widgets.chart