I have a line chart with a date/time x axis. The points have a name that is converted to local time. However, the tick marks are placed at UTC midnight. How can I get them to be placed at local midnight?
To clarify, my localtime is EDT (-04:00). So, at approximately 20:00, the tick mark is shown.
var chart = Highcharts.chart('container', {
"chart": {
"type": "line",
"height": 300,
"marginLeft": 60,
"marginRight": 0,
"spacingLeft": 0,
"spacingRight": 0,
"style": {
"fontSize": 14
},
"zoomType": "x"
},
"tooltip": {
"pointFormat": "{point.y}",
"style": {
"fontSize": 14
}
},
"exporting": {
"enabled": false
},
"title": {
"text": "",
"style": {
"display": "none"
}
},
"subtitle": {
"text": "",
"style": {
"display": "none"
}
},
"legend": {
"enabled": "false"
},
"xAxis": {
"type": "datetime",
"labels": {
"enabled": true,
"style": {
"fontSize": "12px"
}
},
"title": {
"text": null
},
"minTickInterval": 86400000
},
"plotOptions": {
"line": {
"color": "#33aaee",
"step": "true",
"lineWidth": 1
}
},
"credits": {
"enabled": false
},
"series": [{
"data": [{
"x": 1499935040582,
"y": 600.8919674194846,
"name": "Jul 13, 2017 4:37 AM"
}, {
"x": 1500069665426,
"y": 600.3026594460489,
"name": "Jul 14, 2017 6:01 PM"
}, {
"x": 1500133689471,
"y": 600.7274040373635,
"name": "Jul 15, 2017 11:48 AM"
}, {
"x": 1500197550895,
"y": 600.1197607401385,
"name": "Jul 16, 2017 5:32 AM"
}, {
"x": 1500224766324,
"y": 600.2311428390589,
"name": "Jul 16, 2017 1:06 PM"
}, {
"x": 1500247544551,
"y": 600.5511455212492,
"name": "Jul 16, 2017 7:25 PM"
}, {
"x": 1500282216949,
"y": 600.2677789206001,
"name": "Jul 17, 2017 5:03 AM"
}, {
"x": 1500285249151,
"y": 600.3165520296044,
"name": "Jul 17, 2017 5:54 AM"
}, {
"x": 1500472917987,
"y": 600.6858600814295,
"name": "Jul 19, 2017 10:01 AM"
}, {
"x": 1500479945476,
"y": 600.6974345877289,
"name": "Jul 19, 2017 11:59 AM"
}],
"showInLegend": false,
"allowPointSelect": true
}]
});
Here is a fiddle showing this.
Highcharts fiddle
Change you epoch's to a javascript date [new Date(epoch)] this will have the date/time fields show in local time instead of UTC.
"series": [{
"data": [{
"x": new Date(1499935040582),
"y": 600.8919674194846
}, {
"x": new Date(1500069665426),
"y": 600.3026594460489
}, {
"x": new Date(1500133689471),
"y": 600.7274040373635
}, {
"x": new Date(1500197550895),
"y": 600.1197607401385
}, {
"x": new Date(1500224766324),
"y": 600.2311428390589
}, {
"x": new Date(1500247544551),
"y": 600.5511455212492
}, {
"x": new Date(1500282216949),
"y": 600.2677789206001
}, {
"x": new Date(1500285249151),
"y": 600.3165520296044
}, {
"x": new Date(1500472917987),
"y": 600.6858600814295
}, {
"x": new Date(1500479945476),
"y": 600.6974345877289
}],
This should keeps your chart in scale with your local time zone
Found an answer to my problem. I am using moment.js to format the time data, so I changed it from:
chart.series[0].data.push({ x: moment(grp.Time).format('x'),
y: grp.DoubleValue, name: moment(grp.Time).format(this.config.get('momentFullDateTimeFormat')) });
to:
chart.series[0].data.push({ x: moment(grp.Time).utc(true).format('x'),
y: grp.DoubleValue, name: moment(grp.Time).format(this.config.get('momentFullDateTimeFormat')) });
So basically I added the ".utc(true)" to the moment definition for the x value.
Related
Plot bands in highchart export server is not working properly. I want the output same as shown in jsfiddle below.
I want the color plot band to show on y axis with width 20.
This is expected output: https://jsfiddle.net/vc6r8y3n/
Attached image is actual output when we use high-chart export server.
but when I tried same JavaScript json object on
http://export.highcharts.com/
its giving me image with plot band color spread on whole chart. its not considering width for 'y' or 'x' axis in export server. I gave attached image of export chart.
Why highchart behaving differently in both the cases.
Highchart JSON is same as in JSfiddle.
Actual image.
Expected is what it display in Jsfiddle. https://jsfiddle.net/vc6r8y3n/
{
"chart": {
"height": 350,
"width": 600,
"style": {
"fontFamily": "\"Arial\", sans-serif",
"fontSize": "16px"
},
"backgroundColor": "transparent"
},
"title": {
"text": null
},
"credits": {
"enabled": false
},
"legend": {
"align": "center",
"layout": "horizontal",
"verticalAlign": "bottom",
"symbolHeight": 5,
"symbolWidth": 5,
"symbolRadius": 0,
"itemDistance": 10,
"itemStyle": {
"fontSize": "5px",
"fontWeight": "bold",
"fontFamily": "\"Arial\", sans-serif"
},
"borderWidth": 0,
"padding": 0,
"margin": 5
},
"xAxis": {
"categories": [
"Sep-2020",
"Oct-2020",
"Nov-2020",
"Dec-2020",
"Jan-2021",
"Feb-2021"
],
"labels": {
"style": {
"fontSize": "4px",
"fontFamily": "\"Arial\", sans-serif",
"color": "#000"
},
"y": 5
},
"gridLineColor": "transparent",
"gridLineWidth": 0,
"minorGridLineWidth": 0,
"lineColor": "#9A9A9A",
"zIndex": 9999999
},
"yAxis": [
{
"title": {
"text": ""
},
"min": 0,
"max": 100,
"tickInterval": 20,
"plotBands": [
{
"color": "rgb(204,0,0)",
"from": 0,
"to": 30.99,
"zIndex": 3
},
{
"color": "rgb(226,113,113)",
"from": 31,
"to": 44.99,
"zIndex": 3
},
{
"color": "rgb(247,209,34)",
"from": 45,
"to": 54.99,
"zIndex": 3
},
{
"color": "rgb(136,207,136)",
"from": 55,
"to": 68.99,
"zIndex": 3
},
{
"color": "rgb(68,180,68)",
"from": 69,
"to": 87.99,
"zIndex": 3
},
{
"color": "rgb(0,153,0)",
"from": 88,
"to": 100,
"zIndex": 3
}
],
"width": 20
}
],
"plotOptions": {
"column": {
"dataLabels": {
"enabled": true
}
}
},
"series": [
{
"name": "Line1",
"type": "column",
"data": [
{
"y": 61,
"color": "#5b9bd5"
},
{
"y": 41,
"color": "#5b9bd5"
},
{
"y": 21,
"color": "#5b9bd5"
},
{
"y": 81,
"color": "#5b9bd5"
},
{
"y": 31,
"color": "#5b9bd5"
},
{
"y": 71,
"color": "#5b9bd5"
}
],
"color": "#5b9bd5",
"showInLegend": true
},
{
"name": "Line 2",
"type": "column",
"data": [
null,
null,
null,
null,
null,
1
],
"color": "#00B050"
},
{
"name": "Line 3",
"type": "spline",
"data": [
null,
{
"y": 45
},
{
"y": 38
},
{
"y": 32
},
{
"y": 40
},
{
"y": 48
}
],
"color": "#9A0229"
}
]
}
enter image description here
We're using minPointLength property to make points with a value of 0 show up in a stacked column chart. The problem is that now a point with a value of 4 (third column from left in screenshot) is displayed smaller than the minimum height. In the following screenshot the very tiny block with value 4 is hovered and the blocks with 0 are displayed in red.
I expected that blocks with a value bigger than 0 are also bigger than the blocks with a value of 0 or at least same height.
Our overall target is to set a minimum height for all blocks, in a way that all the box labels can be shown.
Here is a fiddle to play around: https://jsfiddle.net/ftmkxdbo/
This is the configuration of our chart:
Highcharts.chart('container', {
"chart": {
"type": "column"
},
"title": {
"text": ""
},
"credits": {
"enabled": false
},
"xAxis": {
"categories": ["10/17", "10/18", "10/19", "10/20"]
},
"yAxis": {
"title": {
"text": ""
},
"stackLabels": {
"enabled": true,
"style": {
"color": "gray"
}
},
"min": 0,
},
"legend": {
"enabled": false
},
"plotOptions": {
"column": {
"stacking": "normal",
"dataLabels": {
"enabled": true,
"style": {
"fontSize": "10px",
"fontWeight": "normal",
"textShadow": "0px"
},
},
"minPointLength": 5,
}
},
"series": [{
"name": "3",
"data": [{
"x": 0,
"y": 3,
}],
"index": 0,
"color": "rgba(120,185,40,0.8)"
}, {
"name": "12",
"data": [{
"x": 0,
"y": 12,
}],
"index": 1,
"color": "rgba(245,155,0,0.8)"
}, {
"name": "19",
"data": [{
"x": 0,
"y": 19,
}],
"index": 2,
"color": "rgba(120,185,40,0.8)"
}, {
"name": "13",
"data": [{
"x": 0,
"y": 13,
}],
"index": 3,
"color": "rgba(120,185,40,0.8)"
}, {
"name": "18",
"data": [{
"x": 1,
"y": 18,
}],
"index": 0,
"color": "rgba(120,185,40,0.8)"
},
// ...
]
});
That is a very problematic issue. Currently the columns overlap because the stacking functionality does not take into account the minPointLength option. If it were otherwise, the total value of the column would be incorrect.
You can see all discussion about this problem on github: https://github.com/highcharts/highcharts/issues/1776
I have a combined xrange and area chart, where I cannot get the area plot to go to the bottom of the chart view.
This is what I would like:
But this is what I'm getting:
Any help would be greatly appreciated.
https://jsfiddle.net/OysteinAmundsen/ad6shmL0/39/
Highcharts.chart('container', {
"chart": {
"borderWidth": 0,
"zoomType": "x",
"animation": false,
"scrollablePlotArea": { "scrollPositionX": 1 },
"height": 200,
"spacing": [0,0,0,0]
},
"scrollbar": { "enabled": true },
"time": { "useUTC": false },
"title": { "enabled": false },
"legend": { "enabled": false },
"colors": [ "#0032FF" ],
"credits": { "enabled": false },
"plotOptions": {
"area": { "threshold": null },
"xrange": { "minPointLength": 1 }
},
"xAxis": {
"type": "datetime",
"labels": { "overflow": "justify" },
"title": { "text": "Date" }
},
"yAxis": {
"lineWidth": 1,
"tickWidth": 1,
"alternateGridColor": "#F2F2F2",
"title": { "enabled": false },
"categories": [ "Closed", "Open" ],
"max": 1,
"min": -1
},
"tooltip": {
"borderRadius": 6,
"borderColor": "#0032FF",
"useHTML": true
},
"series": [
{
"name": "Proximity",
"type": "xrange",
"turboThreshold": 0,
"borderColor": "gray",
"animation": 0,
"pointWidth": 20,
"colors": [
"#0032FF",
"#0b5668"
],
"data": [
{ "x": 1567077909855, "x2": 1567083603287, "y": 1 },
{ "x": 1567077924011, "x2": 1567077924011, "y": 0 },
{ "x": 1567083619442, "x2": 1567083619442, "y": 1 }
]
},
{
//"turboThreshold": 1000,
"type": "area",
"color": "#f9d5d5",
"lineWidth": 0,
"animation": 0,
"data": [
{ "x": 1566728240265, "y": 0, "name": "Lost connectivity" },
{ "x": 1566728240265, "y": 2, "name": "Loss" },
{ "x": 1567077909855, "y": 2, "name": "Gain" },
{ "x": 1567077909855, "y": 0, "name": "Gained connectivity" },
{ "x": 1567085295420, "y": 0, "name": "Lost connectivity" },
{ "x": 1567085295420, "y": 2, "name": "Loss" },
{ "x": 1567085533152, "y": 2, "name": "Gain" },
{ "x": 1567085533152, "y": 0, "name": "Gained connectivity" }
]
}
]
});
Instead of area series type use xAxis.plotBands:
xAxis: {
type: 'datetime',
plotBands: [{
from: 1567079711855,
to: 1567077909855,
color: '#f9d5d5'
}, {
from: 1567082015102,
to: 1567079910825,
color: '#f9d5d5'
}]
}
Demo:
https://jsfiddle.net/BlackLabel/y706czmo
API reference:
https://api.highcharts.com/highcharts/xAxis.plotBands
When I generate my Highchart chart it generates complete. The only thing that doesn't show up is the export option.
Can anybody figure out what I am doing wrong?
Do I need to specify extra CSS styling options of some sort or include another JS script to allow this to work? I can't really figure it out at the moment.
chart1 = new Highcharts.Chart({
"chart": {
"renderTo": "container",
"type": "column"
},
"title": {
"text": "Doorlooptijd exploten"
},
"subtitle": {
"text": "Databron: Digibieb"
},
"xAxis": {
"categories": {
"2": "> xx",
"1": "< xx",
"0": "< xx"
}
},
"yAxis": {
"min": 0,
"title": {
"text": "Aantallen"
}
},
"legend": {
"layout": "vertical",
"backgroundColor": "#FFFFFF",
"align": "left",
"verticalAlign": "top",
"x": 100,
"y": 100,
"floating": 0,
"shadow": 1
},
"exporting": {
"enabled": true
},
"credits": {
"enabled": false
},
"plotOptions": {
"column": {
"pointPadding": 0.2,
"borderWidth": 0
}
},
"series": [{
"name": "asd",
"data": [1, 1, 1]
}, {
"name": "asd2",
"data": [1, 1, 1]
}, {
"name": "asd3",
"data": [1, 1, 1]
}, {
"name": "asd4",
"data": [0, 0, 25]
}, {
"name": "asd5",
"data": [54, 19, 53]
}, {
"name": "asd6",
"data": [0, 0, 4]
}, {
"name": "asd8",
"data": [22, 4, 28]
}, {
"name": "asd7",
"data": [23, 40, 19]
}, {
"name": "asd9",
"data": [23, 13, 8]
}, {
"name": "asd10",
"data": [3, 0, 0]
}]
});
You need to load the exporting.js script like this after the main Highcharts script
<script src="https://code.highcharts.com/highcharts.js"></script>
<script src="https://code.highcharts.com/modules/exporting.js"></script>
Fiddle
I have a Highstock graph with dual pane (top & bottom). I understand that the range selector will read from the xAxis extremes to set the from and to date.
Everytime I add a series, be it to the top or bottom, I will have to invoke : chart.xAxis[0].setExtremes(); in order for the range selector to "refresh" the From and To date (if necessary).
Now, the problem comes when I have to do the same steps for my export module. How do I formulate the extremes into my options array before I pass it to my local export server? Currently, it seems that when I perform the export, the From / To Date is occasionally different from what I have set using xAxis.min and xAxis.max.
Any help/advice is appreciated. Thank you.
UPDATE/EDIT:
I am currently using the following options to generate my chart. The chart's xAxis displayed according to the xAxis' min and max values 1315756800000 (12th sep 2011) and 1338134400000 (28th may 2012). However, if I were to copy the following codes and do export on http://export.highcharts.com/, the date becomes 11th sep 2011 to 27th may 2012. Any idea why?
{
"series": [
{
"data": [
{
"y": 101.3,
"x": 1315756800000
},
{
"y": 101.4228571428,
"x": 1316361600000
},
{
"y": 101.4657142857,
"x": 1316966400000
},
{
"y": 101.47,
"x": 1317571200000
},
{
"y": 101.4714285714,
"x": 1318176000000
},
{
"y": 101.4628571428,
"x": 1318780800000
},
{
"y": 101.4657142857,
"x": 1319385600000
},
{
"y": 101.4542857142,
"x": 1319990400000
},
{
"y": 101.4628571428,
"x": 1320595200000
},
{
"y": 101.4557142857,
"x": 1321200000000
},
{
"y": 101.4614285714,
"x": 1321804800000
},
{
"y": 101.45,
"x": 1322409600000
},
{
"y": 101.4414285714,
"x ": 1323014400000
},
{
"y": 101.44,
"x": 1323619200000
},
{
"y": 101.4514285714,
"x": 1324224000000
},
{
"y": 101.4328571428,
"x": 1324828800000
},
{
"y": 101.4214285714,
"x": 1325433600000
},
{
"y": 101.4614285714,
"x": 1326038400000
},
{
"y": 101.4257142857,
"x": 1326643200000
},
{
"y": 101.4742857142,
"x": 1327248000000
},
{
"y": 101.4785714285,
"x": 1327852800000
},
{
"y": 101.4357142857,
"x": 1328457600000
},
{
"y": 101.3085714285,
"x": 1329062400000
},
{
"y": 101.3071428571,
"x": 1329667200000
},
{
"y": 101.1742857142,
"x": 1330272000000
},
{
"y": 101.1285714285,
"x": 1330876800000
},
{
"y": 101.3242857142,
"x": 1331481600000
},
{
"y": 101.4042857142,
"x": 1332086400000
},
{
"y": 101.4742857142,
"x": 1332691200000
},
{
"y": 101.4771428571,
"x": 1333296000000
},
{
"y": 101.48,
"x": 1333900800000
},
{
"y": 101.4771428571,
"x": 1334505600000
},
{
"y": 101.4642857142,
"x": 1335110400000
},
{
"y": 101.4628571428,
"x": 1335715200000
},
{
"y": 101.4871428571,
"x": 1336320000000
},
{
"y": 101.4757142857,
"x": 1336924800000
},
{
"y": 101.4785714285,
"x": 1337529600000
},
{
"y": 101.475,
"x": 1338134400000
}
],
"color": "#5b0f00",
"type": "line",
"name": "series 1 (mRL)",
"yAxis": "testAxis",
"id": "testSeries1",
"turboThreshold": 3000
},
{
"name": "series 1 (mRL) Min Max Range",
"type": "errorbar",
"id": "primaryWATERLEVELmRLSeries_ErrorBar",
"linkedTo": "testSeries1",
"data": [
[
1315756800000,
101.3,
101.3
],
[
1316361600000,
101.36,
101.5
],
[
1316966400000,
101.44,
101.5
],
[
1317571200000,
101.45,
101.5
],
[
1318176000000,
101.46,
101.5
],
[
1318780800000,
101.45,
101.48
],
[
1319385600000,
101.45,
101.48
],
[
1319990400000,
101.44,
101.47
],
[
1320595200000,
101.44,
101.48
],
[
1321200000000,
101.44,
101.47
],
[
1321804800000,
101.44,
101.47
],
[
1322409600000,
101.42,
101.47
],
[
1323014400000,
101.43,
101.45
],
[
1323619200000,
101.42,
101.46
],
[
1324224000000,
101.44,
101.47
],
[
1324828800000,
101.42,
101.44
],
[
1325433600000,
101.41,
101.43
],
[
1326038400000,
101.45,
101.47
],
[
1326643200000,
101.4,
101.46
],
[
1327248000000,
101.45,
101.49
],
[
1327852800000,
101.46,
101.5
],
[
1328457600000,
101.38,
101.47
],
[
1329062400000,
101.27,
101.37
],
[
1329667200000,
101.28,
101.33
],
[
1330272000000,
101.14,
101.24
],
[
1330876800000,
101.09,
101.18
],
[
1331481600000,
101.21,
101.43
],
[
1332086400000,
101.37,
101.46
],
[
1332691200000,
101.42,
101.5
],
[
1333296000000,
101.47,
101.49
],
[
1333900800000,
101.47,
101.49
],
[
1334505600000,
101.46,
101.5
],
[
1335110400000,
101.42,
101.49
],
[
1335715200000,
101.43,
101.5
],
[
1336320000000,
101.48,
101.5
],
[
1336924800000,
101.46,
101.49
],
[
1337529600000,
101.47,
101.5
],
[
1338134400000,
101.46,
101.5
]
],
"zIndex": "1000",
"yAxis": "testAxis"
},
{
"color": "",
"type": "line",
"name": "series 2",
"yAxis": "testAxis",
"id": "testSeries",
"turboThreshold": 3000
}
],
"yAxis": [
{
"id": "testAxis",
"labels": {
"style": {
"font": "8px Helvetica",
"fontWeight": "normal"
}
},
"title": {
"enabled": true,
"text": "axis label",
"style": {
"font": "8px Helvetica",
"fontWeight": "normal"
}
},
"top": "0%",
"height": "100%",
"opposite": true,
"onGraph": "primary"
}
],
"legend": {
"enabled": true,
"itemStyle": {
"font": "11px Helvetica",
"fontWeight": "normal"
}
},
"xAxis": {
"min": 1315756800000,
"max": 1338134400000
},
"navigator": {
"enabled": true
},
"credits": {
"enabled": false
}
}