Highcharts: plot a number that was too small to detect? - highcharts

I am plotting values on a Highchart for my client. Sometimes she tests for something and the resulting number is too small to be detected (so she doesn't give me a number value). She doesn't want the chart to show a zero, but rather a "non-detect." Does anyone have ideas how to show that?
For example, how do I plot something like "if <.5 then display '<0.5' instead of a number"?
Here are the tables that I am converting into Highcharts (specifically the Microcystin test). The Highcharts are powered by parsing .csv files with PHP. If a value says "<0.5", then I don't want it to be a zero. I want people to know that the test was run, but that the level was too low to register. For now, I'm telling my client to explain that using introductory text, but thought maybe one of you would have a better idea for communicating this.
Note: I can see that she reported a .29 (which is smaller than .5). That looks inconsistent with what I'm asking. Apparently that was tested with a more sensitive test (so it is a valid plot).
Example series:
0.2,
0.66,
23.3,
1.64,
0.29,
<0.5,
0.58,
464,
93.2,
22.9

You can convert such values into very small numbers and show them as data labels and in a tooltip as a <0.5 value.
var data = [0.2, 0.66, 23.3, 1.64, 0.29, '<0.5', 0.58, 464, 93.2, 22.9];
data = data.map(el => isNaN(el) ? 0.0001 : el);
Highcharts.chart('container', {
series: [{
data: data,
dataLabels: {
enabled: true,
formatter: function() {
if (this.y < 0.5) {
return '< 0.5'
}
return this.y;
}
}
}],
tooltip: {
pointFormatter: function() {
var pointVal = this.y < 0.5 ? '< 0.5' : this.y;
return '<span style="color:' + this.color + '">●</span> ' + this.series.name + ': <b>' + pointVal + '</b><br/>'
}
}
});
Live example: http://jsfiddle.net/BlackLabel/0q864fx2/
API Reference:
https://api.highcharts.com/highcharts/series.line.dataLabels.formatter
https://api.highcharts.com/highcharts/tooltip.formatter

Related

How to show an additional column from CSV file as a tooltip in Highcharts

I want to display not only the X/Y values for the graph (in my case the year and the temperature anomaly), but one additional piece of information (i.e. one column) from the CSV file.
That is, I have this Highcharts heat map
and would like to display the RANK in the tooltip as indicated in the CSV:
Year,Y,Temperature Anomaly,Rank
1880,1,-0.12,91
1881,1,-0.09,83
1882,1,-0.1,86
1883,1,-0.18,103
Is that possible? If yes, how? I couldn't find any information on this.
Here is a fiddle.
Thanks for any hints!
Use seriesMapping property to add extra data and display it in a tooltip through tooltip.formatter function:
data: {
...,
seriesMapping: [{
x: 0,
y: 1,
value: 2,
rank: 3
}]
},
tooltip: {
formatter: function() {
return 'Year: ' + this.point.x + ' ' +
'<br /><b>Temp. Anomaly: ' + this.point.value +
' °C </b><br />Rank: ' + this.point.rank;
}
}
Live demo: https://jsfiddle.net/BlackLabel/owqc3pjk/
API Reference: https://api.highcharts.com/highcharts/data.seriesMapping

Setting Additional Data to highcharts tooltip with formatter doesn't work if points count exceed threshold

Trying to attach additional data to series tooltip using tooltip.formatter
There data for series looks like that:
series: [{
name: 'Series 1',
data: [{ x:Math.rand(), label: "Test Label1"},
{ x:Math.rand(), label: "Test Label2"},
{ x:Math.rand(), label: "Test Label3"}
]
}]
And formatter:
tooltip: {
shared: true,
formatter: function() {
var result = '<b>' + Highcharts.dateFormat('%A, %b %e, %Y', this.x) + '</b>';
$.each(this.points, function(i, datum) {
result += '<br />' + datum.point.label;
});
return result;
}
}
The problem is highchart expose additional fields in formatter function only if dots count in series doesn't trespass some threshold. Experimentally I found that it works for less than approximately 250 dots and depends on chart configuration.
Seems there is some internal throttling, but I cannot find any mentions of it in documentation.
There is example demonstrating an issue with 2 charts similar charts,but different series cardinality: 250 and 500 dots respectively - http://jsfiddle.net/k5exP/68/
It is related with the fact that in the highstock you have enabled datagrouping, defaulty. It causes tht points are approximated and custom parameters are skipped.

How to Format Highcharts dataLabels Decimal Points

Can you please take a look at this example and let me know how I can format the dataLabels to be display only with two decimal numbers?
Here is the numver formats which I have in the series
series: [{
name: 'Tokyo',
data: [7.554555, 6.34345559, 9.5555, 14.5555, 18.4333433, 21.5555, 25.2, 26.5333333, 23.33333, 18.23243543, 13.776565669, 9.65454656]
}, {
name: 'London',
data: [3.9, 4.2, 5.7, 8.5, 11.9, 15.2, 17.0, 16.6, 14.2, 10.3, 6.6, 4.8]
}]
and I would like to present them like 7.55 , 6.34, 9.55 . Thanks
You need to combine the dataLabels formatter and Highcharts.numberFormat:
...
dataLabels: {
enabled: true,
formatter: function () {
return Highcharts.numberFormat(this.y,2);
}
}
...
See jsFiddle
I would simply add a the format option to data labels as follows:
dataLabels: {
enabled: true,
format: '{point.y:,.2f}'
}
It's the simple way of doing it without having to define a function using formatter.
extra:
The comma after the colon makes sure that a number like 1450.33333 displays as 1,450.33 which is nice also.
In case someone wants to go "further", I'm showing data that can be 10^1 to 10^9 so I'm converting them and showing the unit afterwards.
Remember, Highcarts deals only with integers so if you want to add units (and not in the YAxis because of multiple units) you can give it in the source data but you have to format them afterwards:
column: {
dataLabels: {
enabled: true,
formatter: function () {
// Display only values greater than 0.
// In other words, the 0 will never be displayed.
if (this.y > 0) {
if (this.y >= Math.pow(10, 9))
{
return Highcharts.numberFormat(this.y /Math.pow(10, 9) , 1) + " mias";
}
else if (this.y >= Math.pow(10, 6))
{
return Highcharts.numberFormat(this.y /Math.pow(10, 6) , 1) + " mios";
}
else
{
return Highcharts.numberFormat(this.y, 0);
}
}
},
mias : stands for "milliards" (french translation of billiards)
mios : stands for "millions" (french translation of millions)
I noticed in the comments you wanted to not display trailing zeroes.
This was the simplest solution I was able to muster:
...
dataLabels: {
enabled: true,
formatter: function () {
return parseFloat(this.y.toFixed(2)).toLocaleString();
}
}
...
If you don't want the number to end up with a comma-separator (depending on locale) remove the .toLocaleString().
Sidenote: Unfortunately using format (instead of formatter and a js func like we do above) is limited to a subset of float formatting conventions from the C library function sprintf, as indicated here on highcharts website. That library has the code g that would automatically do this for us but unfortunately it is not implemented in Highcharts :(, i.e. format: '{point.y:,.2g}' does not work.

how to have customized tooltip,when plot has two series

Suppose i have a plot with two series one is OHLC and Line.I want to customize tool tip like for example i don't want to show to time stamp, Open and High value of OHLC series in tool tip and i want add some customized message to line series tool tip.
How to achieve customized tool tip in Highchart?
http://jsfiddle.net/ZZAR5/1/
$(function () {
// create the chart
$('#container').highcharts('StockChart', {
rangeSelector: {
selected: 2
},
title: {
text: 'AAPL Stock Price'
},
series: [{
type: 'ohlc',
data: [
[1147996800000, 63.26, 64.88, 62.82, 64.51],
[1148256000000, 63.87, 63.99, 62.77, 63.38],
[1148342400000, 64.86, 65.19, 63.00, 63.15],
[1148428800000, 62.99, 63.65, 61.56, 63.34],
[1148515200000, 64.26, 64.45, 63.29, 64.33],
[1148601600000, 64.31, 64.56, 63.14, 63.55],
[1148947200000, 63.29, 63.30, 61.22, 61.22],
[1149033600000, 61.76, 61.79, 58.69, 59.77]
]
}, {
type: 'line',
data: [
[1147996800000, 63.26],
[1148256000000, 63.87],
[1148342400000, 64.86],
[1148428800000, 62.99],
[1148515200000, 64.26],
[1148601600000, 64.31],
[1148947200000, 63.29],
[1149033600000, 61.76]
]
}]
});
});
You can control the format of the tooltip using the formatter function in the tooltip block. For example:
tooltip: {
formatter: function () {
var s = '<b>' + this.x + '</b>';
$.each(this.points, function (i, point) {
s += '<br/>' + point.series.name + ': ' + point.y;
});
return s;
},
shared: true
},
This formats the tooltip using a header of the x value, and lists series name and y for each series. shared: true means the tooltip is shared between both series, appearing the same no matter which series you hover over.
There is plenty of documentation on the tooltips along with some examples here:
http://api.highcharts.com/highcharts#tooltip.formatter
and also here:
http://api.highcharts.com/highstock#tooltip.formatter

Highchart - yAxis - 1,000 should be displayed like 1000

I can't find the settings for my problem in the Highchart API.
I've cerated an example on jsFiddle http://jsfiddle.net/qErT2/
How can I swap 1,000 into 1000 ??
Greetings
HighChart number format is the same like PHP NUMBER FORMATS
you can use this format any where
for tooltip
tooltip: {
formatter: function ()
{
return '<b>' + this.series.name + '</b><br/>' + this.x + ' - <b>' + Highcharts.numberFormat(this.y, 0,'',''); + '</b>';
}
}
for yAxis
yAxis: {
labels: {
formatter: function () {
return Highcharts.numberFormat(this.value, 0,'','');
}
}
},
YOUR EXAMPLE MODIFIED DEMO (tooltip)
AND UPDATED DEMO (tooltip and yAxis labels)
Take look at lang options http://api.highcharts.com/highcharts#lang and obviously you can use Highcharts.numberFormat() http://api.highcharts.com/highcharts#Highcharts.numberFormat() which can be used in tooltip formater / label formatter to display numbers as you need.
http://api.highcharts.com/highcharts#yAxis.labels.formatter

Resources