-
Notifications
You must be signed in to change notification settings - Fork 154
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix tooltip when displaying multiple series #66
Conversation
We replace the "%x" in the tooltip string with the corresponding item tick's label. We do so by looking at the item's index in the chart's data array (dataIndex), and getting the tick in the same index in the ticks' array. That works fine if you have a single series, but doesn't work with multiple ones. In that case, you have multiple data arrays, one for each series, but you still have a single ticks array. For example, if you have the plot's data as: [ { data: [ ["Foo", 5] ] }, { data: [ ["Bar", 10] ] } ] Both item's dataIndex will be 0, because each one is the first element on its series' data array. But the ticks array is something like: ["Foo", "Bar"] If you use only dataIndex, you'll get the tick "Foo" for both items. What we need is an offset which tells us which series the current item is in: that's seriesIndex. The ticks' index is then calculated as ```seriesIndex + dataIndex```. That solves our problem. In our example, even though the dataIndex for both items is 0, the seriesIndex for "Foo" is 0, and for "Bar" is 1. Everything works as expected. This fixes krzysu#65.
Fix tooltip when displaying multiple series
Thanks! 👍 |
With the last version I'm not able to get it works.
but also:
it doesn't work: in the second series tip I get the label of the next value. This is what, I think, is normally because in the second series is taken the n+1 index of the array
removing the patch now it works:
|
@nicola883 Does your first example fails without the patch? I would expect your second example to work without this patch, but not the first one. |
The first example doesn't work with and without patch.
I see that in this case:
is an array of 6 elements, all the elements of the two series in sequence, so the patch could considers the number of the elements before that requested. |
@nicola883 Could you create an example at jsbin.com (or any other similar service) showing the error you're getting? |
I came across the same problem as nicola883, and removing the "patch" fixed my issue. I'm using a stacked bar graph with three columns, and have them named High, Med, Low and they correlate to 2, 1, and 0 respectively. Since dataIndex and seriesIndex are being added and then "item.series.xaxis[ticks].length > tickIndex" is being ran my code never hits "content = content.replace(xPattern, item.series.xaxis[ticks][tickIndex].label);" for the "top stacked" option and thus it displays the index # (0, 1, or 2) instead of the label. Sorry for only the explanation but I cannot post my code on jsbin due to legal reasons; however, I hope my explanation made sense. |
I had the same problem and removing the "patch" also fixed my issue. |
I've reopened the associated issue (#65). If you have any additional information, please discuss it there and I'll look into this when I get the chance. |
I faced this issue while testing scenarios for the plug-and-play analytics panel I'm building here. In my case, as you might see when you select multiple series (what are labelled "Series" in the example I link to), using the in-built feature to dynamically construct the label content via a function solves this for me. My approach is something like this for bar, line and scatter charts:
And this for the Pie chart:
Test this on the project demos here. So, perhaps those still facing this issue can adopt this approach as the project finds a better solution for those wanting to use the format string approach in the docs. |
We replace the "%x" in the tooltip string with the corresponding item tick's
label. We do so by looking at the item's index in the chart's data array
(dataIndex), and getting the tick in the same index in the ticks' array.
That works fine if you have a single series, but doesn't work with multiple
ones.
In that case, you have multiple data arrays, one for each series, but you still
have a single ticks array. For example, if you have the plot's data as:
Both item's dataIndex will be 0, because each one is the first element on its
series' data array. But the ticks array is something like:
If you use only dataIndex, you'll get the tick "Foo" for both items. What we
need is an offset which tells us which series the current item is in: that's
seriesIndex. The ticks' index is then calculated as
seriesIndex + dataIndex
.That solves our problem. In our example, even though the dataIndex for both
items is 0, the seriesIndex for "Foo" is 0, and for "Bar" is 1. Everything
works as expected.
This fixes #65.