The following is the formatter I am using.
Tooltip tooltip = new Tooltip();
tooltip.setxDateFormat("MMM dd, YYYY");
tooltip.setFormatter("function() { var d = new Date(this.x);" + "return " + "'<b>'+this.series.name +'</b><br/>"
+ "<strong>Value :</strong> '+ this.y +'<br/>" + "<strong>Start Date :</strong> '+ this.x; " + "}");
chartConfig.setTooltip(tooltip);
How to:
1) Round of value with two decimal places
2) Using Date Format like Nov 30, 2016
Kindly assist.
Vaadin Charts uses Highcharts on the client side, which means that you can use Highcharts JS APIs for formatting, the following calls should work:
Highcharts.numberFormat(this.y, 2)
Highcharts.dateFormat('%b %d %Y', new Date(this.x))
Related
Highcharts: I have a shared tooltip with 3 default bullets. I need to add custom information to the 3rd bullet (or series).
I need Bullet C to show its default value, but also show what percentage it is of Bullet B. In the screenshot below, Bullet C would say: "Good Condition: 3,448 (32% of Assessed).
My question is 2 parts:
How do I customize only the third bullet tooltip?
How do I find out what percentage of Bullet B is represented by Bullet C? (in my example, 3,448 is 32% of 10,697, but how do i find that using highcharts?)
Update: This code formats the bullet and partially answers my first question (except it's missing the comma for thousands format):
return '<span style="color:' + this.series.color + '">● </span>' + this.series.name + ':<b>' + this.y + '</b><br/>';
You can define individual tooltip options for a series, in your case you need to use pointFormatter function, for example:
series: [..., {
...,
tooltip: {
pointFormatter: function() {
var series = this.series.chart.series,
percentage = Highcharts.numberFormat(
this.y / series[1].points[this.index].y * 100,
2
);
return '<span style="color:' +
this.color + '">●</span> ' +
this.series.name + ': <b>' +
Highcharts.numberFormat(this.y, 0) +
'</b> Percentage: ' + percentage + '%<br/>'
}
}
}]
Live demo: http://jsfiddle.net/BlackLabel/6m4e8x0y/4955/
API Reference:
https://api.highcharts.com/highcharts/series.column.tooltip
https://api.highcharts.com/class-reference/Highcharts#.numberFormat
I am plotting UTC timestamps for an particular user whose timezone I know. Each data point is in the format "2018-06-19 13:19:52.000Z" and was added to the series of points to be plotted as moment("2018-06-19 13:19:52.000Z").tz(this.tiemZone).valueOf().
When the point is plotted, it is plotted as 6/19 13:19:52, but I would like this to be plotted in the user's timezone, so something like 6/19 6:19:52.
I read that Highcharts plots in UTC, but that if I set useUTC: false (somewhere), that it would plot in the current browser's timezone, but I actually want to plot in the user's timezone, e.g. if the timezone is "Los Angeles", then the above time would be 6:19:52.
time = new window.Highcharts.setOptions({
time: {
timezone: _that.timeZone,
timezoneOffset: _that.offset
}
}, this);
return '<b>' + this.series.name + '</b><br/>' +
Highcharts.dateFormat('%m/%d %H:%M:%S',
this.x)
+ ' - ' + Highcharts.numberFormat(this.y, 2) + ' ' + toolTipUnits;
The offset I calculated after taking the moment of one of the UTC timestamps:
moment(data[0][0]).tz(this.timeZone)._offset, here is was equal to -420
I tried something the above, but the tooltip still shows the UTC time 13:19:52. Any advice?
************************ UPDATE*****************************
time = new Highcharts.setOptions({
global: {
timezone: _that.timeZone,
timezoneOffset: _that.offset
}
}, this);
return '<b>' + this.series.name + '</b><br/>' +
Highcharts.dateFormat('%m/%d %H:%M:%S', this.x)
+ ' - ' + window.Highcharts.numberFormat(this.y, 2) + ' ' + toolTipUnits;
I updated the code as shown above, and now the data point is being plotted as 6/19 20:19:52, even though I am adding -420 to the data point (this.x). Looking into this, but any idea why?
It looks to me like you're simply going in the opposite direction.
From the Highcharts API documentation, it says "positive values are west, negative values are east of UTC." If you assume 6/19 13:19:52 is UTC time, and you want 6/19 6:19:52 (seven hours west of UTC), then you'll want to set a positive number for your offset (timezoneOffset: 420). What you're doing now is setting a negative number (-420), so it's returning an offset for seven hours east of UTC.
https://api.highcharts.com/highcharts/time.timezoneOffset
I hope this is helpful for you.
(Also, can I assume that in your return code, you're using this in the tooltip formatter?)
I am trying to get the following output in highcharts...
Have a list of supporting values for a specific point and show in the tooltip all of those supporting values on that single point.
my solution is to use the formatter()
formatter: function () {
var res = 'The value for <b>' + this.x + '</b> is <b>' + this.y + '</b><br/>';
for(var i = 0; i < this.point.supportingData.list.length; i++){
res += this.point.supportingData.list[i].name + '<br/>';
}
return res;
}
example.... point (x,y) has 12, 17, 53 and 27
I want all of those valuse to appear on the hover over on point (x,y).
The problem is that I want my formatter to be split like this.
http://jsfiddle.net/207xt4an/
Where the x value is on the bottom of the chart and everything else that comes with that jsfiddle.
Is there a way to accomplish this using formatter? Or vise versa, grab all of the supporting in the pointFormat?
No problem doing this with Area chart, but can't find a way to do it for scatter charts. Used http://jsfiddle.net/uZXPR/1/ as a starting point but it's only 1 series and has no special formatting. I've tried numerous stabs in the dark but no luck so far. I could submit all those failed attempts here but I think it'd be quicker to start from http://jsfiddle.net/uZXPR/1/ and just add what's needed.
There are some indications that others are having problems with multiple series scatter chart tooltips, but of course particulars are different in every case.
Here's a snippet of how I do it with Area chart (the gNs.format* functions are just local homegrown formatting routines):
tooltip: {
formatter: function() {
var s = '<b>' + gNs.formatDate(new Date(this.x), '%Y-%M-%d') + '</b>';
$.each(this.points, function(i, point) {
s +='<br/>' +
'<span style="color:' + point.series.color + '">' + point.series.name + '</span>' +
': ' +
gNs.formatSeconds2HMS(point.y); });
return s;
},
shared: true
},
Sample code:
formatToolTip: function() {
var tt = this.x + ' = ' + this.y + ' (this.percentage + ' %)';
return tt;
}
this.percentage is always undefined. I am a newbie working with highcharts 3.0.0
This is an old example of how you can use the formatter function to get the %. It relies on knowing the max value of the data, but you can use the getExtremes() method to pull that from the chart.
http://jsfiddle.net/jlbriggs/H3Q9h/5/
var pcnt = Highcharts.numberFormat((this.y / 415 * 100),0,'.');
http://api.highcharts.com/highcharts#Axis.getExtremes%28%29
replace the 415 in the equation with a variable set as the dataMax value of the getExtremes() method.