Programatically set the marker on a plot

☆樱花仙子☆ 提交于 2019-11-28 12:54:25

I have come up with some answer. I think @Mark might know a better option if he knows how to popup the highlighter. Since I know how to get appropriate position that you are after, just I am not sure how to call the highlighter then to paint at this coordinates.

Here goes my answer.

I am simply getting the coordinates of the grid in pixels. Then grabbing highlight canvas and painting a circle there, beforehand always calling replot() to have a fresh plot. Try using the button few times to see how it goes over every point of the data. If you know guys how to improve it, for example, how to avoid reploting each time, then please do let me know.

jpm

you could just implement the draw function that is used in the highlight plugin as shown here. Another option could be to change the plugin itself and create a new event or expose the draw function etc.

The highlighted marker will change as soon as you move your mouse over another marker in the line chart, but this is to be expected.

It would be nice to have the tooltip shown when the marker is set to highlighted.

function DoSomeThing(plot) {

    var hl = plot.plugins.highlighter;
    var s = plot.series[0];
    var smr = s.markerRenderer;
    var mr = hl.markerRenderer;
    mr.style = smr.style;
    mr.lineWidth = smr.lineWidth + hl.lineWidthAdjust;
    mr.size = smr.size + hl.sizeAdjust;
    var rgba = $.jqplot.getColorComponents(smr.color);
    var newrgb = [rgba[0], rgba[1], rgba[2]];
    var alpha = (rgba[3] >= 0.6) ? rgba[3]*0.6 : rgba[3]*(2-rgba[3]);
    mr.color = 'rgba('+newrgb[0]+','+newrgb[1]+','+newrgb[2]+','+alpha+')';
    mr.init();
    mr.draw(s.gridData[3][0], s.gridData[3][1], hl.highlightCanvas._ctx);
}

If you want to change the color try modifying your options string with new series colors, because that function only returns the clicked point. But you have to change the color manually by yourself.

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