Highcharts: Different tick interval in the same axis - highcharts
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/
Related
How to properly plot UTC data in Highcharts if labels do not match x-axis?
I have a series of data points (UTC date and value) that I need to plot using Highcharts, which by default uses UTC. However, the data can be in different user timezones, so in this example I am setting it to New York. I noticed that even though the tooltip on each of my data points is correct, e.g. those for 10/26, some of them seem to be plotted in the section of the plot corresponding to 10/27. I expect all 9 data points for 10/26 to be plotted before the 10/17 mark. Does anyone see the issue in my code? I have created a JSFIFFLE to illustrate the issue clearly. var timeZone = 'America/New_York'; var timeZoneOffsetValue = moment(values[0].data[0][0]).tz("America/New_York")._offset; console.log(timeZoneOffsetValue); Highcharts.chart('container', { yAxis: { gridLineWidth: 0.5, gridLineColor: '#D6D6D6', tickInterval: 5, dashStyle: 'LongDash', lineColor: '#D6D6D6' }, xAxis: { type: 'datetime', dateTimeLabelFormats: { day: '%m/%d', week: '%d/%b', month: '%b/%y', year: '%Y' }, title: { enabled: true, text: 'date' }, gridLineWidth: 0, lineColor: '#D6D6D6', lineWidth: 0.5, startOnTick: true }, plotOptions: { scatter: { marker: { radius: 5, states: { hover: { enabled: true, lineColor: 'rgb(100,100,100)' } } }, states: { hover: { marker: { enabled: false } } }, tooltip: this.toolTip } }, chart: { marginTop: 5, marginRight: 0, reflow: false, backgroundColor: 'rgba(255, 255, 255, 0.1)', style: { fontFamily: 'Open Sans' }, type: 'scatter', spacingBottom: 0, spacingTop: 0, spacingLeft: 0, spacingRight: 0 }, tooltip: { formatter: function () { var time = new Highcharts.setOptions({ global: { timezoneOffset: -timeZoneOffsetValue } }, this); var s = '<b>' + Highcharts.dateFormat('%m/%d %H:%M:%S', this.x) + ' - ' + Highcharts.numberFormat(this.y, 2); return s; }, }, series: values }); http://jsfiddle.net/thehme/a47Lbnwr/25/ Note: in my actual code, I have noticed that sometimes when I first load the plot, most of the time the 3 data points are in the 10/27 slot, but if I reload the plot, then sometimes the data points move into the 10/16 date range. This is what makes this more confusing.
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/
Highcharts mixed column/spline, wrong xaxis labels
I am trying to finalize a graph where I report the daily production within a month and a couple of other daily based series. The graph is always set at full scale, meaning that I always show all the days within a month, even if I do not have values for them, whichever is the reason why. On the first day of each month, I display the graph of the previous month, as a report. This is the jfiddle I've set up so that you can have an idea. The problem I've been fighting against is that, whatever I try to do, Highcharts simply ignores me and displays wrong labels on x axis. So the days start from 2, go throughout the whole month to the last and they end with 1. This is the code for my chart: $(function() { var chart = new Highcharts.Chart({ chart: { renderTo: 'tab-month-graph', zoomType: 'xy' }, title: { text: 'Daily - August 2015' }, xAxis: { type: 'datetime', tickInterval: 24 * 3600 * 1000, labels: { align: 'center', text: 'Giorni', style: { fontSize: '10px', fontFamily: 'Verdana, sans-serif' } }, dateTimeLabelFormats: { day: '%e' } }, yAxis: [{ // Primary yAxis title: { text: 'Produzione giornaliera', style: { color: Highcharts.getOptions().colors[1] } } }, { // Secondary yAxis title: { text: 'PR giornaliero', style: { color: Highcharts.getOptions().colors[0] } }, min: 0, startOnTick: false, opposite: true }], legend: { enabled: false }, series: [{ name: 'Prod.', type: 'column', data: [[1438466230000, 4603.36],[1438552630000, 4264.92],[1438639030000, 3108.05],[1438725430000, 2047.03],[1438811830000, 2270.39],[1438898230000, 2258.2],[1438984630000, 3971.95],[1439071030000, 3784.45],[1439157430000, 3674.53],[1439243830000, 3131.95],[1439330230000, 1963.13],[1439416630000, 3333.52],[1439503030000, 4161.8],[1439589430000, 4408.59],[1439675830000, 2968.83],[1439762230000, 2808.05],[1439848630000, 4439.77],[1439935020000, 3746.48],[1440021430000, 4980],[1440107830000, 3683.91],[1440194230000, 4480.78],[1440280630000, 4406.48],[1440367030000, 4518.98],[1440453430000, 4492.73],[1440539830000, 3924.14],[1440626230000, 4062.89],[1440712630000, 3225.47],[1440799030000, 3213.75],[1440885430000, 4631.95],[1440971830000, 4471.17],[1441058230000, 4223.91]], color: '#89CE7F', dataLabels: { enabled: true, rotation: -90, color: '#000000', align: 'right', x: 4, y: 10, style: { fontSize: '11px', fontFamily: 'Verdana, sans-serif', textShadow: '0 0 3px black' } } }, { name: 'PR', type: 'spline', yAxis: 1, lineWidth: 0, marker: { radius: 6 }, data: [[1438466230000, 73.36],[1438552630000, 75.08],[1438639030000, 57.54],[1438725430000, 38.85],[1438811830000, 39.14],[1438898230000, 63.78],[1438984630000, 76.03],[1439071030000, 75.78],[1439157430000, 77.61],[1439243830000, 79.74],[1439330230000, 77.35],[1439416630000, 73.98],[1439503030000, 75.79]], color: '#AA0000', tooltip: { valueSuffix: ' %' } }, { name: 'PR Cont.', type: 'spline', yAxis: 1, lineWidth: 0, marker: { radius: 5, symbol: 'circle' }, data: [[1438466230000, 78.84],[1438552630000, 79.85],[1438639030000, 75.16],[1438725430000, 59.15],[1440971830000, 78.5],[1441058230000, 78.45]], color: '#BBBB00', tooltip: { valueSuffix: ' %' } } ], tooltip: { xDateFormat: '%A, %d %B %Y', valueSuffix: ' kW', shared: true // LEGENDA CONDIVISA }, plotOptions: { series: { pointStart: Date.UTC(2015, 7, 1), pointRange: 24 * 3600 * 1000 } } }); }); I've read tons of posts on Stack Overflow, tried tons of suggestions, I've even tried this post tinyurl.com/psbzxeh on HighCharts official forum which is referred to a similar problem, but it did not solve my issue. Could someone point me out to the right solution?
Just to clarify things: columns look like translated by one day, because of that time (21:57:10 UTC) - which is almost another day (without UTC it's 23:57:10 for GMT+2:00). In general, if you have daily data, then it's better to use 00:00:00 as this is when exactly date starts. Manipulating JSON shouldn't be that hard, see: function modify(data) { var time; data.map(function(e) { time = new Date(e[0]); time.setUTCHours(0); time.setUTCMinutes(0); time.setUTCSeconds(0); e[0] = time.getTime(); return e; }); return data; } And: series: [{ name: 'Prod.', type: 'column', data: modify([ [1438466230000, 4603.36], ... ]) }] Demo: http://jsfiddle.net/p7vnqmt7/3/ Note: to remove extra tick at the last place on the axis, you can simply set xAxis.max. And to answer question in the comment: no, pointInterval shouldn't be used when you have data as x-y pair.
try below function above your highchart function and set xAxis min and max. Use very first timestamp(date) as min and last timestamp(date) as max value. $( function () { Highcharts.setOptions( { lang : { rangeSelectorZoom : ' ' }, global : { useUTC : false } } ); } );
grouping date in Highcharts if the date range is too big
I am using Highcharts to show some statistic for my customer but I have problem when the customer select long data range here is the first image for my highchart in the default view and if I select too long date range here is the result here is my code $(function () { var chart; $(document).ready(function() { chart = new Highcharts.Chart({ chart: { renderTo: 'container', type: 'line', marginRight: 50, marginBottom: 80, dataGrouping: { enabled: true } }, title: { text: 'Visits Statistics', x: -20 //center }, credits: { text: '', href: '' }, subtitle: { text: '', x: -20 }, xAxis: { categories: [<?php print $categories; ?>], labels: { rotation: -45, align: 'right', style: { fontSize: '10px', fontFamily: 'Verdana, sans-serif' } } }, yAxis: { title: { text: 'Visits' }, min: 0, plotLines: [{ value: 0, width: 1, color: '#808080' }] }, tooltip: { formatter: function() { return '<b>'+ this.x +' '+'</b><br/>'+ this.y +'Hit'; } }, legend: { layout: 'vertical', align: 'right', verticalAlign: 'top', x: -10, y: 10, borderWidth: 0 }, series: [{name:'from 2011-09-1',data: [<?php print $visits; ?>]}] }); }); });
Highcharts can automatically manage time values in the x-Axis, provided that your chart is configured correctly. The problem in your case is that you've told Highcharts to use your categories, and it shows all of the categories. To set up your chart to avoid this, you'll need to do two things: Set the x-Axis type to datetime Make sure that your data is formatted correctly Or, use pointStart and pointInterval if you can't mess around with the data. Using your example: // ... xAxis: { //remove categories and set type as 'datetime' type: 'datetime', labels: { rotation: -45, align: 'right', style: { fontSize: '10px', fontFamily: 'Verdana, sans-serif' } } }, // ... series: [{ name:'from 2011-09-1', // since you probably don't want to change your data, we leave it alone... data: [<?php print $visits; ?>], // ... and instead, set `pointStart` and `pointInterval` pointStart: Date.UTC(2011, 8, 1), // September 1, 2011 pointInterval: 24 * 3600 * 1000 // each point is 1 day (measured in milliseconds) }]
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,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4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,3,3,3,3,3,3,3,3,3,3,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,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/