is there any way to pass some additional data to the series object that will use to show in the chart 'tooltip'?
for example
tooltip: {
formatter: function() {
return '<b>'+ this.series.name +'</b><br/>'+
Highcharts.dateFormat('%b %e', this.x) +': '+ this.y;
}
here we can only use series.name , this.x & this.y to the series. lets say i need to pass another dynamic value alone with the data set and can access via series object. is this possible?
Thank you all in advance.
I am using AJAX to get my data from SQL Server, then I prepare a js array that is used as the data in my chart. JavaScript code once the AJAX is successfull:
Now to show extra meta-data in the tooltip:
I use a DataRow to iterate through my result set, then I use a class to assign the values prior to passing back in Json format. Here is the C# code in the controller action called by Ajax.
I realize there is a more efficient and acceptable way to code in C# but I inherited the project.
Just to add some kind of dynamism :
Did this for generating data for a stacked column chart with 10 categories.
I wanted to have for each category 4 data series and wanted to display additional information (image, question, distractor and expected answer) for each of the data series :
In the highcharts section:
Hope it helps someone.
Additionally, with this solution, you can even put multiple data as much as you want :
Thank you Nick.
Yes, if you set up the series object like the following, where each data point is a hash, then you can pass extra values:
In your tooltip you can access it via the "point" attribute of the object passed in:
Full example here: https://jsfiddle.net/burwelldesigns/jeoL5y7s/
For time series data, especially with enough data points to activate the turbo threshold, the proposed solutions above will not work. In the case of the turbo threshold, this is because Highcarts expects the data points to be an array like:
In order not to lose the benefits of the turbo threshold (which is important when dealing with lots of data points), I store the data outside of the chart and look up the data point in the tooltip
formatter
function. Here's an example:This approach will work for all chart types.