开发者

Highlighter ( jquery-jqplot) with 3 values (instead of 2)

开发者 https://www.devze.com 2023-02-21 05:26 出处:网络
I\'m using the jquery plugin jqplot. I have a tuple with three elements, on the graph the first element of tuple is the xaxis and yaxis is the second element. Highlighter needs to show the x, y and th

I'm using the jquery plugin jqplot. I have a tuple with three elements, on the graph the first element of tuple is the xaxis and yaxis is the second element. Highlighter needs to show the x, y and the third element of the tuple. Something like:

curve1=[**[x,y,date],** [1, 2,'28-May-11'], [2, 4,'30-May-11'], [3,7,'31-May-11']];

Highlighter shows: (1 , 2 , '28-May-11') on first point, (2,4,'30-May-11') on sec开发者_运维问答ond...

Any ideas?


One solution involves a small modification to jqplot.highlighter.js in the showTooltip method. In this method the following line is used to assign the html to the tooltip element:

elem.html(str);

For your purposes, you can override this assignment with the following:

elem.html('(' + neighbor.data[0] + ', ' + neighbor.data[1] + ', ' + neighbor.data[2] + ')');

as neighbor.data is being used to represent your tuple containing the 3 values: x, y, and date.

Alternatively...

A more general purpose solution would allow the tooltip text to be dynamically generated from the front end (rather than dealing with a fixed formatting strategy within highlighter.js). In this case you could replace the above change with the following:

elem.html(neighbor.data[2]);

And then change your tuple's third element from the date (which I'm assuming is only being used for the purposes of the tooltip) to the tooltip text itself.

For example your tuple might look like:

curve1=[ [1, 2, '(1, 2, 28-May-11)'], [2, 4, '(2, 4, 30-May-11)'], [3,7, '(3, 7, 31-May-11)'] ];

or even this:

curve1=[ [1, 2, 'On 28-May-11 there were 2 instances.'], [2, 4, 'Then on 30-May-11 there were 4.'], ...];

Hope that helps.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号