5

I am trying to turn pointLabels on and off programmatically. I thought it would work something like this:

    var data_ = [[1,1],[2,5],[4,9]];
    var graph = $.jqplot(id_graph, [data_], {
        series:[{pointLabels: { show:true } }]
        }
      );
    graph.series[0].pointLabels.show=false;
    graph.replot();

However, this still displays the point labels.

Thanks for any help!

3 Answers3

3

althoug this post is old I found a solution for the problem:

var data_ = [[1,1],[2,5],[4,9]];
var graph = $.jqplot(id_graph, [data_], {
    series:[{pointLabels: { show:true } }]
    }
  );
graph.series[0].plugins.pointLabels.show=false;
graph.replot();

Instead of using

graph.series[0].pointLabels.show=false;

use

graph.series[0].plugins.pointLabels.show=false;

In my case this worked.

Stefan
  • 61
  • 5
1

I think what you want is actually showMarker option. Since in this code you are not setting point labels therefore they will never be show. The showMarker will let you switch the dots of the graph on/off.

Is that what you are in fact after? Otherwise please provide an example that you use.

Here is a sample made for a similar issue.

Please see this sample. There on the button click the change of makers visibility occurs.


Update: This sample shows the solution, which uses the approach presented above, i.e. re-plotting the plot while changing the 'pointLabels' new parameter.

jQuery(document).ready(function () {
    var data = [
        [1, 1],
        [2, 5],
        [4, 9]
    ];
    var graph;
    var isShowPointLabels = true;

    function makePlot(showPointLabels) {
        graph = $.jqplot("chart", [data], {
            series: [{
                pointLabels: {
                    show: showPointLabels
                }
            }]
        });
    }
    makePlot(isShowPointLabels);
    $("#click").click(function () {
        isShowPointLabels = !isShowPointLabels;
        makePlot(isShowPointLabels);
        graph.replot();
    });
});

In this case I couldn't figure out how to use drawSeries(...) to re-plot just a single series, as @Mark shows for marker, which would be a good practice to do here.

Community
  • 1
  • 1
Boro
  • 7,913
  • 4
  • 43
  • 85
  • OP wanted to hide pointLabels, not markers. That is a huge difference because it works differently than markers. – Mroz Nov 14 '13 at 13:19
  • @Mark do you know how to apply the `drawSeries(...)` method in this case, to update the plot when changing of the `pointLabels` parameter? Mroz is right I have originally presented a solution for `marker` show/hide rather than as OP requested `pointLabels` thus I corrected my answer. Though I do not know how to apply the method in this case. Please assist. Cheers. – Boro Nov 14 '13 at 19:44
1

Adding to Boro's answer, if you want to toggle the marker on a single series, it would be quicker to do:

graph.drawSeries({markerOptions:{show:false}},seriesIndex); //redraw single series

Calls to replot can be expensive with a large number of series.

Revved fiddle here.

Mark
  • 106,305
  • 20
  • 172
  • 230
  • +1 this works noticeably faster, particularly if you test it with a larger data set. @Mark would you by any chance know a similar solution that would substitute use of the `replot()` method in case your plot's `div` was resized, for example, because someone resized the browser's window? – Boro Jun 02 '12 at 18:50
  • 1
    @Boro, if you are re-scaling the axis (ie recalculating the value to pixel position), you are stuck with a replot call. It is the only one that will recalculate the autoscaling. Essentially the fastest to slowest is this: drawSeries, just redraw the canvas associated with one series, redraw, redraws all the elements in the plot but does not redo the value to pixel positions, and then replot, redraws all the elements and recalculates the axis scaling. – Mark Jun 03 '12 at 14:12
  • Thank you Mark for this explanation. So far I had experience using 'replot' since I was serving resize but as you are saying its use here is not appropriate. – Boro Jun 05 '12 at 12:29