How to make Highstock work with two xAxis? - highcharts

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/

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/

The point's gap affects the width of columns of highcharts. Bug?

I have set both a column and a line in one chart, such as the link:
https://jsfiddle.net/dodouwang/wtjbgav0/1/
Highcharts.chart('container', {
xAxis: {
type: 'datetime',
},
plotOptions: {
column: {
turboThreshold: 10000,
borderWidth: 0,
pointPadding: 0,
groupPadding: 0
},
},
series: [{
type: 'column',
name: 'column',
data: [[1497484800000,210000],[1497571200000,120000],[1497744000000,190000]]
},{
type: 'line',
name: 'line_wide',
data: [[1497484800000,210000],[1497571200000,120000]]
},{
type: 'line',
name: 'line_narrow',
data: [[1497484800000,210000],[1497498000000,120000]],
visible: false
}],
});
But I found that if the gap between the points of the line is too narrow(less than one day), then the width of the column is automatic set to no wider than the gap. Is it a bug or a feature?
you can visit the link above, the default show is a column with a "wider" line, it seems all right. But if you unselect the "line_wide" and select the "line_narrow", then the bug accurs.
How to fix it?
P.S.: I have another question of this link's column: I have set the xAxis to 'datetime', and the column data is [[1497484800000,210000],[1497571200000,120000],[1497744000000,190000], and set the Gapping to 0 to make the width of the column as wider as possible. But, when there are only column in the chart(the 2 lines are unselected), why the max width of the column is a "day", not an "hour" or a "minute" or other width?
What you need is series.pointRange option. Width of the column depends on that value and if it is not configured - the range will be computed as the distance between the two closest data points (on axis, so each series which have that specific axis will be taken into the account).
If you set pointRange to 1 day, columns widths will span for 1 day:
plotOptions: {
column: {
turboThreshold: 10000,
borderWidth: 0,
pointRange: 1000 * 3600 * 24,
pointPadding: 0,
groupPadding: 0
},
},
example: https://jsfiddle.net/nogfr6js/

Highcharts: difficulties with variable width columns

This is a follow-up from Highcharts: incorrect column placement with linked series? but I felt that this issue warranted a new post rather than a continuation of the comments in the above post.
Basically a bit of a hack is required in order to implement variable width columns. That hack is to use multiple series... one series per column width required.
But that hack leads to an issue with placement of columns, and another hack is required to move them to the right place.
But that creates an issue with a big gap between the edge of the chart area and the y axis. So another hack is required to eliminate the gap.
But that seems to create yet another issue, which is that it messes up the left-most data points in any other series on the chart.
This is illustrated in the following jsfiddle:
http://jsfiddle.net/drmrbrewer/215tnLna/33/
You'll see that something funny is happening when the cursor is over the left-most two columns. If you un-share the tooltip, the problem appears to be that the tooltip is not operating at all on the left-most two spline points.
Any way to resolve this? It's a shame you can't just have variable column widths as a native feature, specifying a column width per point...
Thanks.
jsfiddle code is as follows:
$(function () {
$('#container').highcharts({
title: {
text: 'Variable width columns'
},
xAxis: {
type: 'datetime',
tickInterval: 36e5,
labels: {
format: '{value:%H}'
},
// following are to eliminate gaps:
min: 1428048000000-36e5 + (6 * 0.5 * 36e5),
max: 1428127200000-36e5 - (6 * 0.5 * 36e5)
},
// seems to be a combination of min above
// and tooltip.shared below that freezes the
// left-most two columns
tooltip: {
shared: true
},
legend: {
enabled: false
},
plotOptions: {
column: {
groupPadding: 0,
pointPadding: 0,
borderWidth: 0,
grouping: false,
color: '#22CC00'
}
},
series: [{
name: 'spline',
yAxis: 0,
type: 'spline',
zIndex: 5,
data: [{"x":1428048000000,"y":8.6},{"x":1428051600000,"y":9},{"x":1428055200000,"y":8.1},{"x":1428058800000,"y":6.6},{"x":1428062400000,"y":5},{"x":1428073200000,"y":4.9},{"x":1428084000000,"y":4},{"x":1428094800000,"y":3.4},{"x":1428105600000,"y":2.4},{"x":1428127200000,"y":6.9}],
color: '#2222CC'
},
// now the multiple series of columns having different widths, linked together...
{
name: 'column',
type: 'column',
data: [{"x":1428048000000,"y":8.6},{"x":1428051600000,"y":9},{"x":1428055200000,"y":8.1},{"x":1428058800000,"y":6.6},{"x":1428062400000,"y":5}],
pointRange: 36e5,
// following is to position the bars correctly
pointPlacement: -0.5*(3/6)*(1/3)
},{
name: 'column',
type: 'column',
data: [{"x":1428073200000,"y":4.9},{"x":1428084000000,"y":4},{"x":1428094800000,"y":3.4},{"x":1428105600000,"y":2.4}],
linkedTo: ':previous',
pointRange: 3 * 36e5,
// following is to position the bars correctly
pointPlacement: -0.5*(3/6)
},{
name: 'column',
type: 'column',
data: [{"x":1428127200000,"y":6.9}],
linkedTo: ':previous',
pointRange: 6 * 36e5,
// following is to position the bars as I want them
pointPlacement: -0.5
}]
});
});

Highcharts Highstock align x-axis gridlines with center of data point

I'm using Highcharts Highstock chart to display daily data. The vertical (x-axis) gridlines do not align with the data point (gridline is to the left of the data point). Does anyone know how to align the gridline with the data point?
http://jsfiddle.net/kngz3exf/3/
Highcharts.setOptions({
global: {
useUTC: false
}
});
$(function () {
$('#container').highcharts('StockChart', {
rangeSelector: {
enabled: false
},
yAxis: {
gridLineWidth: 0
},
xAxis: {
gridLineColor: '#000000',
gridLineWidth: 1,
lineColor: '#000000',
tickColor: '#000000',
minorGridLineColor: '#000000',
minorGridLineWidth: 1,
minorTickColor: '#000000',
ordinal: true,
tickInterval: 86400000,
minorTickInterval: 86400000
},
series: [{
data:[
[1417410000000, -0.4818850000000001],
[1417496400000, -0.40866199999999997],
[1417582800000, 0.20889499999999994],
[1417669200000, -0.623542],
[1417755600000, -0.060399999999999995],
[1418014800000, -0.56108],
[1418101200000, 0.30852700000000005],
[1418187600000, -0.4492829999999999],
[1418274000000, -0.275211],
[1418360400000, 0.013063999999999965],
[1418619600000, -0.27293900000000004],
[1418706000000, 0.49981200000000003],
[1418792400000, 0.2362090000000001],
[1418878800000, 0.4464490000000003],
[1418965200000, 1.2100639999999998],
[1419224400000, -0.792635],
[1419310800000, 0.14788899999999994],
[1419397200000, 0.011684],
[1419570000000, 0.08526699999999998],
[1419829200000, -0.12494599999999997],
[1419915600000, -0.06489100000000003],
[1420002000000, 0.279632]
]
}]
});
});
By changing my date format from ticks to Date.UTC(yyyy, mm, dd), I can get the data point to align with the vertical grid line.
What you need to do is set the useUTC to false. Now your Dec 2nd data show on Dec 2nd axis tick. Note that your data is not going to hit every major tick mark - looks like you are skipping weekends but your axis is not.

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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,6,6,6,6,6,6,6,6,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,4,4,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/

Resources