Highcharts Date/Time and X-Axis - highcharts
I am looking for a simple example of how to make the time display in one hour increments for a 24 hour period, a la: 8 AM, 9 AM, etc... along the x-axis. The data to be charted will be as follows [time, meter-reading]. All of my attempts to date have not worked.
Please advise if further details need to be provided.
After playing with an official example and the documentation, I found a way to get intervals every two hours but you can get easily intervals every hour.
Here are the options you have to define in your Highcharts creation:
$(function () {
$('#container').highcharts({
chart: { ... },
title: { ... },
subtitle: { ... },
xAxis: {
type: 'datetime',
tickInterval: 3600 * 1000,
...
},
yAxis: { ... },
tooltip: { ... },
legend: { ... },
plotOptions: { ... },
series: [{
...
pointInterval: 3600 * 1000,
pointStart: Date.UTC(2006, 0, 01, 0, 0, 0, 0),
data: [
...
]
}]
});
});
Playing with the tickInterval, pointInterval and pointStart options, you can obtain what you want.
Here is a live example of what I am talking about: http://jsfiddle.net/FxD58/1/
It works very well if you have 24 values in series (like the 24 hours in a day...)
Related
Highcharts: Different tick interval in the same axis
I have a series that is composed of: Daily values, until a certain date 6-monthly values, from that date onward I'd like to increase the tick interval exclusively for the second part of the chart, so I can compact the data. To be clear, I want the same space that represents one month on the left side of the chart to represent 6 months on the right side. I'm not sure if Highcharts allows this... I think there can be two different approaches: Create two series with two different axis and set one axis after the other Set different tickInterval for the same axis. Using tickPositions and tickPositioner I've only managed to show more or less ticks, but always keeping their position on the time axis. This is my code: Highcharts.chart('container', { chart: { zoomType: 'xy', animation: false }, title: { text: 'Some data' }, legend: { verticalAlign: 'bottom', borderWidth: 0 }, xAxis: { type : 'datetime', tickInterval: 30 * 24 * 3600 * 1000, labels: { useHTML: true, rotation: -90 }, dateTimeLabelFormats: { // don't display the dummy year month: '%b-%y', year: '%Y' }, plotLines: [{ color: 'gray', dashStyle: 'longdashdot', value: 1536278400000, width: 1, label: { text: 'Selected Date' } }] }, yAxis: { title: { text: null }, maxZoom: 0.1 }, series: jsonData }); Here's a jsfiddle with a subset of my original data. Which would be the best way to achieve this?
Highcharts does not allow it by default, but you can use a workaround. You can create two xAxis with right size proportion and two series, like in an example below: xAxis: [{ type: 'datetime', endOnTick: false, tickInterval: 30 * 24 * 3600 * 1000, max: 1536278400000, width: '65%', labels: { useHTML: true, rotation: -90 }, dateTimeLabelFormats: { // don't display the dummy year month: '%b-%y', year: '%Y' }, plotLines: [{ color: 'gray', dashStyle: 'longdashdot', value: 1536278400000, width: 1, label: { text: 'Selected Date' } }] }, { min: 1536278400000, startOnTick: false, offset: 0, type: 'datetime', tickInterval: 180 * 24 * 3600 * 1000, labels: { useHTML: true, rotation: -90 }, dateTimeLabelFormats: { // don't display the dummy year month: '%b-%y', year: '%Y' }, width: '35%', left: '65%' }] Live demo: https://jsfiddle.net/BlackLabel/zxd4j5tn/
How to make Highstock work with two xAxis?
The navigator in Highstock only seems to affect the first xAxis. The second xAxis, as in the example linked to below, isn't rescaled, and always shows all data. See jsfiddle below: https://jsfiddle.net/wardrop/t9ug4pm7/7/ Does anyone know how to fix this?
You can set extremes in the second axis manually after extremes are set in the first axis. xAxis: [{ type: 'datetime', minRange: 24 * 3600000, // 1 day labels: { align: "left", rotation: 45 }, dateTimeLabelFormats: { day: '%e %b %Y' }, events: { afterSetExtremes: function (e) { this.chart.xAxis[1].setExtremes(e.min, e.max, true, false); } } }, example: https://jsfiddle.net/t9ug4pm7/9/ You can also linked two axis, so the linked axis' extremes will follow after the master axis. But for columns it is needed to define pointRange because without it, columns might be drawn incorrectly. , { //axis type: 'datetime', linkedTo: 0, // linked to master axis minRange: 24 * 3600000, lineWidth: 0, tickWidth: 0, labels: {enabled: false}, opposite: true } series: [{ id: 'daily', name: 'Daily', type: 'column', color: 'rgb(124, 181, 236)', data: data['daily'], pointRange: 1000 * 3600 * 24, }, example: https://jsfiddle.net/t9ug4pm7/11/
Highstock and data units : how to specify data unit?
It is 00h03, I am sweating hard and I am done. I am looking for a good soul to give me a hand with Hightcharts.js's Hightstock options. I have this simple jsFiddle: https://jsfiddle.net/hsolatges/p4k7ery7/1/ highstockOptions = { chart: { zoomType: 'x', animation: false }, navigator: { adaptToUpdatedData: false, baseSeries: 1 }, scrollbar: { enabled: false }, rangeSelector: { enabled: false }, yAxis: [{ title: { text: 'REFERENCE' } }], series: [{ type: 'line', name: 'Reference', data: dataset, downsample: { threshold: 1000 // 0 disables downsampling }, turboThreshold: 0 }] }; My data is an array of arrays of coordinates [x, y]. Full dataset is a 90,000 points from 0 to 60 minutes. I want labels in minutes, ticks in minutes, navigator showing me minutes. All I would like to do is telling to Highstock that my dataset arguments are in minutes, not dates, not milliseconds. Just minutes! I have spent hours. And as trivial as it might be, it turns me crazy. Thanks folks!
Highchart - Set Time(Hour:Minute) on X axis
I did not able to get labels like [12:00,12:15,12:30,12:45,01:00,01:15,..] on X axis. I got only 00:00 on X axis.I was not able to display increasing time values on X axes. I want to start default from 12:00. I used following code. xAxis: { type: 'datetime', tickInterval : 1.5 * 3600 * 1000, dateTimeLabelFormats : { day : '%H:%M' } }
This worked for me in Dynamic Highchart. $(document).ready(function () { chart = new Highcharts.Chart({ chart: { renderTo: 'container', defaultSeriesType: 'spline', events: { load: requestData } }, title: { text: 'Sensor Data Vs. Time' }, xAxis: { type: 'datetime', tickPixelInterval: 150, maxZoom: 20 * 1000 }, yAxis: { minPadding: 0.2, maxPadding: 0.2, title: { text: 'Value', margin: 80 } }, series: [{ name: 'Sensor Data', data: [] }] }); }); With this I am displaying Hours, Minutes and seconds as well.
You haven't shown us what data you are supplying. Something like this works: series: [{ name: 'Temperatures', pointStart: new Date().getTime(), pointInterval: 24 * 3600 * 1000, data: [1.5 * 60 * 1000,1.2 * 60 * 1000,2.5 * 60 * 1000,1.9 * 60 * 1000,], }] http://jsfiddle.net/Fusher/pQ5EC/12/
DateTime xAxis Label Not Displaying Correct
I have a data set which is loading correctly but the xAxis label is not displaying the same as JSFiddle using the format specified. The JSFiddle share below is the exact code I am using and it displays perfect with the day of the week Sun - Sat. However, when I run it in my application it displays 00:00 and 12:00 repeated for each the 7 days. The only code change in JSFiddle was the data loading from eval(data.d.Histogram) to the actual array. http://jsfiddle.net/ddelella/bZmtT/ $(function () { Highcharts.setOptions({ global: { useUTC: false } }); $('#container').highcharts({ chart: {}, credits: { enabled: false }, title: { text: null }, legend: { enabled: false }, plotOptions: { series: { borderWidth: 0, pointPadding: -.3 } }, xAxis: { tickLength: 2, minPadding: 0, maxPadding: 0, type: 'datetime', dateTimeLabelFormats: { day: '%a' } }, yAxis: { title: { text: null }, allowDecimals: false, min: 0, gridLineWidth: 0 }, series: [{ data: [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,2,2,2,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,5,5,5,5,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,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0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], type: 'column', name: 'Tractor Quantity', pointStart: Date.parse("12/31/1899 00:00"), pointInterval: (24/288) * 3600 * 1000 }] }); });
It is caused by other date formats, which are default ones, for example, set hour: '%a' and probably will work. See fixed example for one graph, and one with reproduced issue: http://jsfiddle.net/bZmtT/1/