Dynamically disable serie with EnhancedLegendRenderer

1,730 views
Skip to first unread message

giuly...@gmail.com

unread,
Sep 23, 2013, 9:02:16 AM9/23/13
to jqplot...@googlegroups.com
Hi,

I'm quite new to the jqplot's world and I need your help!
I would like to draw a chart with two series and enable series on/off toggling.
I installed the EnhancedLegendRenderer plugin to do so, but now I would like to show the chart with the second series hidden by default: user should click on the legend to see the second chart. 
How can I solve this problem?

Thank you for your help
Giulia

thien thang phan

unread,
Oct 2, 2013, 5:08:43 AM10/2/13
to jqplot...@googlegroups.com
Hi Giuly,

it's an interesting question, I tried to look around on settings for this problem too, and I found that, jqplot didn't support to do that by settings. You have to do it by yourself. 
I was thinking about simple solution is after jqplot created, you trigger click event on the legend which you want to hide it by default.
Take a look on this example: http://jsfiddle.net/JWhmQ/2470/
I used an example of another guy and modify a little bit on it. You will see this block:

var legends = $("td.jqplot-table-legend-label");
for (var i = 0; i < legends.length; i++) {
    if($(legends[i]).text() == "Staff Appearance") {
        $(legends[i]).trigger("click");
    }
}

Hope it help :)

giuly...@gmail.com

unread,
Oct 3, 2013, 5:13:19 AM10/3/13
to jqplot...@googlegroups.com
Thank you for your help, but I solved copying EnhancedLegendRenderer's plugin code:

   var series_to_hide_idx = 1;
   var s = my_plot.series[series_to_hide_idx ];
   s.canvas._elem.hide();
   my_plot.legend._elem.find('td').eq(sidx * 2).addClass('jqplot-series-hidden');
   my_plot.legend._elem.find('td').eq((sidx * 2) + 1).addClass('jqplot-series-hidden');

Bye
Giulia

thien thang phan

unread,
Oct 6, 2013, 9:31:39 AM10/6/13
to jqplot...@googlegroups.com
ywc, great to know a new way ;)


--
You received this message because you are subscribed to a topic in the Google Groups "jqplot-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/jqplot-users/wY0KeALDejE/unsubscribe.
To unsubscribe from this group and all its topics, send an email to jqplot-users...@googlegroups.com.
To post to this group, send email to jqplot...@googlegroups.com.
Visit this group at http://groups.google.com/group/jqplot-users.
For more options, visit https://groups.google.com/groups/opt_out.

Siddhartha Chinthapally

unread,
Dec 30, 2013, 5:05:12 AM12/30/13
to jqplot...@googlegroups.com
You could also try Series.toggleDisplay
plot.series[series_index].toggleDisplay( { data: {} });

--Sid

Purva Chimanpure

unread,
Oct 29, 2014, 7:37:03 AM10/29/14
to jqplot...@googlegroups.com
Hi,

Is there any option for horizontal scrollbar on jqplot chart?

burakerk

unread,
Oct 15, 2015, 6:37:55 AM10/15/15
to jqplot-users
thien thang phan


$(legends[i]).trigger("click");
brilliant idea, saved my days. Thank you very much.

Larry Martell

unread,
Oct 15, 2015, 2:45:37 PM10/15/15
to jqplot-users
It would be nice if you quoted some of the post you are replying to to
give this some context. I have no clue what this refers to.

saini...@gmail.com

unread,
Jul 7, 2018, 9:34:49 PM7/7/18
to jqplot-users
Hi Thien thang phan

Thanks a lot for this post, its working for me. Hiding the bars whichever I want.
But still i am facing some problems, I am using five series in stack bar chart and hiding first series, it is hiding properly but whenever I do mouse hover for series first it is showing bar for series first as well as tool tip.

Actually I am using jqplot with Primefaces.

So could you help me

saini...@gmail.com

unread,
Jul 7, 2018, 9:45:20 PM7/7/18
to jqplot-users
Hi,

I added EnhancedLegendRenderer's .js in my project and tried with code that you provided but it is not working for me.
I would like to know that what is  my_plot in your code it is id or some thing.
Because I am using jqplot with Primeface so I tried like.

   var series_to_hide_idx = 1;
   var s = PF('myChartId').cfg.series[series_to_hide_idx ];
   s.canvas._elem.hide();
   PF('myChartId').cfg.legend._elem.find('td').eq(sidx * 2).addClass('jqplot-series-hidden');
   PF('myChartId').cfg.legend._elem.find('td').eq((sidx * 2) + 1).addClass('jqplot-series-hidden');

this code give me error something like _elem is not property and find() is not method.
Could you please help me.

Thanks a lot.
Reply all
Reply to author
Forward
0 new messages