turning pointLabels on and off in jqplot

好久不见. 提交于 2019-12-12 11:37:29

问题


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!


回答1:


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.




回答2:


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.




回答3:


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.



来源:https://stackoverflow.com/questions/10810030/turning-pointlabels-on-and-off-in-jqplot

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!