Using highcharts x-axis "zones" for datetime series chart - highcharts

I've got a two-series Highcharts column chart that I'm trying to modify the color between past and future. I'd like the colors in past to be green, and colors in future to be blue essentially. I've read about highcharts "zones" which allow you to change attributes on the axis after a point, but the documentation uses a simple data chart, and not a datetime version like I'm using.
How can I use these zones with a datetime chart, or better-- how can I change the border/fill color of my bars for future instead of default colors used.
http://www.highcharts.com/docs/chart-concepts/series#zones
https://jsfiddle.net/x4n91jL8/
$(function () {
var colors = Highcharts.getOptions().colors;
colors[0] = 'rgba(255,255,255,0)';
colors[1] = '#7FC69E';
$('#container').highcharts({
"credits": {
"enabled": false
},
"chart": {
"renderTo": "container",
"type": "area",
"alignTicks": false,
"height": 300,
"marginLeft": 1,
"marginBottom": 1,
"backgroundColor": "transparent",
"events": {}
},
"title": {
"enabled": false,
"text": ""
},
"plotOptions": {
"series": {
"pointPadding": 0,
"groupPadding": 0.02,
"marker": {
"enabled": false
}
},
"column": {
"animation": false,
"grouping": false,
"pointPadding": 0,
"borderWidth": 0,
"allowPointSelect": false,
"events": {}
},
"line": {
"allowPointSelect": false,
"events": {}
},
"area": {
"allowPointSelect": false,
"events": {}
}
},
"legend": {
"enabled": false,
"layout": "horizontal",
"align": "center",
"verticalAlign": "top",
"floating": true,
"backgroundColor": "#FFFFFF"
},
"tooltip": {
"enabled": false,
"shared": true
},
"rangeSelector": {
"enabled": false,
"inputEnabled": true
},
"xAxis": {
"gridLineColor": "transparent",
"zIndex": 3,
"minorTickInterval": 604800000,
"minorTickPosition": "inside",
"minorTickLength": 5,
"minorTickWidth": 1,
"minorGridLineWidth": 0,
"startOnTick": false,
"gridLineWidth": 1,
"type": "datetime",
"min": 1451800000000,
"max": 1457000000000,
"labels": {
"enabled": false,
"step": 1
},
"dateTimeLabelFormats": {
"month": "%b",
"year": "%Y"
}
},
"series": [
{
"name": "Duration",
"zIndex": 3,
"type": "column",
"data": [
[
1452470400000,
6.5
],
[
1453075200000,
11.25
],
[
1453680000000,
8.25
],
[
1454284800000,
6.55
],
[
1454889600000,
1.05
],
[
1455494400000,
4.633333333333333
],
[
1456099200000,
1.1666666666666667
],
],
"tooltip": {
"yDecimals": 0
},
"borderWidth": 1,
"borderColor": "#008244",
"opacity": 0.6,
"lineWidth": 1,
"states": {
"hover": {
"lineWidth": 1
}
},
"zoneAxis": "x",
"zones": [
{
"value": 1454284800000
},
{
"borderColor": "#566888"
}
],
"_colorIndex": 0
},
{
"name": "Duration",
"zIndex": 3,
"type": "column",
"data": [
[
1454284800000,
5.216666666666667
],
[
1454889600000,
0
],
[
1455494400000,
2.6666666666666665
],
[
1456099200000,
1.1666666666666667
],
],
"tooltip": {
"yDecimals": 0
},
"borderWidth": 0,
"borderColor": "#008244",
"opacity": 0.6,
"lineWidth": 1,
"states": {
"hover": {
"lineWidth": 1
}
},
"zoneAxis": "x",
"zones": [
{
"value": 1454284800000
},
{
"fillColor": "#566888"
}
],
"_colorIndex": 1
}
],
"yAxis": [
{
"labels": {
"enabled": false
},
"opposite": false,
"gridLineWidth": 0,
"minorGridLineWidth": 0,
"showEmpty": false,
"title": {
"text": "",
"align": "middle",
"style": {
"color": "rgba(255,255,255,0)"
}
},
"lineWidth": 1,
"min": 0,
"startOnTick": false,
"endOnTick": false,
"max": 16.875,
"lineColor": "rgba(255,255,255,0)",
"index": 0
}
]
});
});

The correct format is actually like this:
And it also requires Highcharts 4.1.4 (I was using an older 4.0.4 actually).
"zones": [
{
"value": new Date().getTime(),
"color":'#7FC69E'
}
}

Related

How do I make the x-axis category label in a polar chart of HighChart non-wordwrap?

Here is the source code:
https://jsfiddle.net/24zrbqpL/
Highcharts.chart('container', {
"chart": {
"type": "line",
"polar": true
},
"xAxis": {
"min": 0.5,
"max": 6.5,
"categories": ['Clarify Objectives', 'Propose Initiates', 'Prioritise & Select', 'Track Performance', 'Review Portfolio', 'Adjust Course', ''],
"labels": {
"distance": 25
},
"tickmarkPlacement": "on",
"lineWidth": 0,
"gridLineColor": "#575756",
"title": {
"style": {
"fontFamily": "\"Lucida Grande\", \"Lucida Sans Unicode\", Verdana, Arial, Helvetica, sans-serif",
"color": "#666666",
"fontSize": "30px",
"fontWeight": "normal",
"fontStyle": "normal"
}
}
},
"yAxis": {
"plotBands": [{
"from": 1,
"to": 2,
"color": "#f8c4c0",
"outerRadius": "105%",
"thickness": "50%"
}, {
"from": 2,
"to": 3,
"color": "#f39d96",
"outerRadius": "105%",
"thickness": "50%"
}, {
"from": 3,
"to": 4,
"color": "#ee766d",
"outerRadius": "105%",
"thickness": "50%"
}, {
"from": 4,
"to": 5,
"color": "#eb584d",
"outerRadius": "105%",
"thickness": "50%"
}],
"reversed": true,
"min": 1,
"max": 5,
"allowDecimals": false,
"tickInterval": 1,
"tickAmount": 6,
"tickLength": 10,
"gridLineInterpolation": "polygon",
"gridLineColor": "",
"lineWidth": 0,
"tickmarkPlacement": "between",
"tickPixelInterval": 100,
"tickPosition": "outside",
"labels": {
"enabled": true,
"style": {
"fontWeight": "bold"
},
//"y": 25
}
},
"title": {
"text": "APM Spiderweb"
},
"series": [{
data: [1, 2, 3, 4, 5, 6]
}, {
}],
"plotOptions": {
"series": {
"animation": true,
"lineWidth": 4,
"marker": {
"radius": 8,
"symbol": "circle"
},
"_colorIndex": 0,
"_symbolIndex": 0
}
},
"credits": {
"enabled": false
},
"colors": [
"#7cb5ec",
"#90ed7d",
"#f7a35c",
"#8085e9",
"#f15c80",
"#e4d354",
"#2b908f",
"#f45b5b",
"#91e8e1"
]
});
Setting a whiteSpace to 'nowrap' in the labels.style object is a solution which you are looking for.
"labels": {
"distance": 25,
"style": {
"whiteSpace": 'nowrap'
}
},
Demo: https://jsfiddle.net/BlackLabel/edpcjL3k/
API: https://api.highcharts.com/highcharts/xAxis.labels.style

Highcharts xAxis has extra gap when multiple yAxis

We have a chart that plots multiple series at once.
There are the main y-series (line type) that will have the main data readings.
There is the option to set two different 'levels' (line types) on the y-axis as well.
There are also options to have multiple additional y-axis bars (bar types).
With the x-axis being the datetime
Here is what a typical example of a chart looks like with valid date for the given range
This is working as expected.
We have the main y-series as the average air temp (left y-axis)
Then we have two bars, one for rainfall and one for irrigation (right y-axis)
And then the two 'levels', one red and one blue.
This is all great.
However, when we go to a date range in the future, where there is no air temp data, we get the following
Note that the start date is 2 days before the date range, and the end date looks equal distance from the end of the 'levels'
Interestingly if we remove the bars we get the following
This now shows the 'levels' to span the full width of the chart
If we remove the lines and just have the bars then we get the following (which is how it should look, but with the 'levels')
There seems to be something in here that is causing the conflict when there are multiple y-series without the main y-series.
I am setting the xAxis.setExtremes to the start and end dates of the date range we are looking at, but that seems to be doing nothing.
Here is the config;
{
"chart": {
"type":"line",
"animation": {
"duration":150
},
"events":{}
},
"credits":{
"enabled":false
},
"title":{
"text":""
},
"subtitle":{
"text":""
},
"tooltip":{
"shared":true,
"crosshairs":true,
"borderWidth":0,
"followPointer":true,
"useHTML":true,
"headerFormat":"<span style=\"font-size: 10px;\">{point.key}</span><br><br>"
},
"xAxis":[
{
"id":"x-axis",
"type":"datetime",
"crosshair":{
"snap":false
},
"title":{
"text":"25th Sep 2019 - 1st Oct 2019",
"margin":15
}
}
],
"yAxis":[
{
"id":"y-axis-sensors",
"title":{
"text":"ºC"
},
"reversed":false,
"visible":true,
"endOnTick":false,
"startOnTick":false,
"alignTicks":false
},
{
"id":"y-axis-moisture",
"title":{
"text":"mm"
},
"opposite":true,
"min":0,
"endOnTick":false,
"startOnTick":false,
"alignTicks":false,
"tickWidth":0,
"gridLineWidth":0
}
],
"series":[
{
"type":"line",
"yAxis":"y-axis-sensors",
"marker":{
"enabled":false
},
"lineWidth":1,
"animation":false,
"name":"Full",
"seriesGroup":"levelSeries",
"id":"series-level-range-full",
"color":"#31B5E0",
"showInLegend":false,
"states":{
"hover":{
"enabled":false
}
},
"enableMouseTracking":false,
"zIndex":5,
"step":true,
"data":[
[1569369600000,5],
[1569974400000,5]
]
},
{
"type":"line",
"yAxis":"y-axis-sensors",
"marker":{
"enabled":false
},
"lineWidth":1,
"animation":false,
"name":"Refill",
"seriesGroup":"levelSeries",
"id":"series-level-range-refill",
"color":"#D23333",
"showInLegend":false,
"states":{
"hover":{
"enabled":false
}
},
"enableMouseTracking":false,
"zIndex":5,
"step":true,
"data":[
[1569369600000,17],
[1569974400000,17]
]
},
{
"type":"column",
"yAxis":"y-axis-moisture",
"marker":{
"enabled":false
},
"name":"Rainfall",
"seriesGroup":"rainfallSeries",
"states":{
"hover":{
"enabled":false
}
},
"id":"series-rainfall",
"pointWidth":6,
"borderWidth":0,
"color":"rgba(41, 182, 246, 0.3)",
"data":[
[1569488400000,5]
],
"zIndex":10,
"stacking":"normal",
"stack":"moisture"
},
{
"type":"column",
"yAxis":"y-axis-moisture",
"marker":{
"enabled":false
},
"states":{
"hover":{
"enabled":false
}
},
"name":"Irrigation",
"seriesGroup":"irrigationSeries",
"id":"series-irrigation",
"pointWidth":6,
"borderWidth":0,
"color":"rgba(205,220,57, 0.3)",
"data":[[1569574800000,3]],
"zIndex":10,
"stacking":"normal",
"stack":"moisture"
}
]
}
I am at a bit of a loss here as to why this is happening.
Can anyone shed some light on this?
One of the solutions can be to add additional x-axis and bind line series to it. Then it looks like your expected result. Check demo and code posted below.
Code:
Highcharts.chart('container', {
"chart": {
"type": "line",
"animation": {
"duration": 150
},
"events": {}
},
"credits": {
"enabled": false
},
"title": {
"text": ""
},
"subtitle": {
"text": ""
},
"tooltip": {
"shared": true,
"crosshairs": true,
"borderWidth": 0,
"followPointer": true,
"useHTML": true,
"headerFormat": "<span style=\"font-size: 10px;\">{point.key}</span><br><br>"
},
"xAxis": [{
"id": "x-axis1",
"type": "datetime",
"crosshair": {
"snap": false
},
"title": {
"text": "25th Sep 2019 - 1st Oct 2019",
"margin": 15
}
}, {
"id": "x-axis2",
visible: false,
"type": "datetime"
}],
"yAxis": [{
"id": "y-axis-sensors",
"title": {
"text": "ºC"
},
"reversed": false,
"visible": true,
"endOnTick": false,
"startOnTick": false,
"alignTicks": false
},
{
"id": "y-axis-moisture",
"title": {
"text": "mm"
},
"opposite": true,
"min": 0,
"endOnTick": false,
"startOnTick": false,
"alignTicks": false,
"tickWidth": 0,
"gridLineWidth": 0
}
],
"series": [
{
"type": "line",
xAxis: 'x-axis2',
"yAxis": "y-axis-sensors",
"marker": {
"enabled": false
},
"lineWidth": 1,
"animation": false,
"name": "Full",
"seriesGroup": "levelSeries",
"id": "series-level-range-full",
"color": "#31B5E0",
"showInLegend": false,
"states": {
"hover": {
"enabled": false
}
},
"enableMouseTracking": false,
"zIndex": 5,
"step": true,
"data": [
[1569369600000, 5],
[1569974400000, 5]
]
},
{
"type": "line",
xAxis: 'x-axis2',
"yAxis": "y-axis-sensors",
"marker": {
"enabled": false
},
"lineWidth": 1,
"animation": false,
"name": "Refill",
"seriesGroup": "levelSeries",
"id": "series-level-range-refill",
"color": "#D23333",
"showInLegend": false,
"states": {
"hover": {
"enabled": false
}
},
"enableMouseTracking": false,
"zIndex": 5,
"step": true,
"data": [
[1569369600000, 17],
[1569974400000, 17]
]
},
{
"type": "column",
xAxis: 'x-axis1',
"yAxis": "y-axis-moisture",
"marker": {
"enabled": false
},
"name": "Rainfall",
"seriesGroup": "rainfallSeries",
"states": {
"hover": {
"enabled": false
}
},
"id": "series-rainfall",
"pointWidth": 6,
"borderWidth": 0,
"color": "rgba(41, 182, 246, 0.3)",
"data": [
[1569488400000, 5]
],
"zIndex": 10,
"stacking": "normal",
"stack": "moisture"
},
{
"type": "column",
xAxis: 'x-axis1',
"yAxis": "y-axis-moisture",
"marker": {
"enabled": false
},
"states": {
"hover": {
"enabled": false
}
},
"name": "Irrigation",
"seriesGroup": "irrigationSeries",
"id": "series-irrigation",
"pointWidth": 6,
"borderWidth": 0,
"color": "rgba(205,220,57, 0.3)",
"data": [
[1569574800000, 3]
],
"zIndex": 10,
"stacking": "normal",
"stack": "moisture"
}
]
});
<script src="https://code.highcharts.com/highcharts.js"></script>
<div id="container"></div>
Demo:
https://jsfiddle.net/BlackLabel/juwc8f37/

highcharts strange area offset error when combined with xrange

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

Render line chart across the plotting area

Highcharts line chart, how to render across plot area.
Trying to render the line chart using HighCharts library to span across the entire plotting area. Using xAxis.min was able to make sure the start is from 0 on xAxis, however, not able to figure out how to make it end where chart plot area ends.
$(function() {
$('#container').highcharts({
"chart": {
"margin": null,
"stacking": "normal",
"height": "250px",
"animation": false,
"events": {}
},
"plotOptions": {
"series": {
"dataLabels": {
"enabled": true,
"inside": true,
"align": "right",
"format": "",
"style": {}
},
"inside": true
}
},
"title": {
"text": null
},
"subtitle": {
"text": null
},
"xAxis": {
"title": {
"text": null,
"align": "high",
"rotation": 0,
"style": {},
"y": null,
"x": null
},
"plotLines": [],
"categories": [
"2019-06-10",
"2019-06-17"
],
"tickInterval": 1,
"tickPositions": [
1
],
"labels": {
"style": {},
"useHTML": true,
"align": ""
},
min: 0.5
},
"legend": {
"enabled": true,
"layout": "horizontal",
"align": "center",
"verticalAlign": "bottom",
"floating": false,
"x": 0,
"y": 0,
"symbolPadding": null,
"symbolRadius": null,
"itemStyle": {},
"itemDistance": null
},
"yAxis": [{
"title": {
"text": "",
"align": "high",
"rotation": 0,
"style": {}
},
"labels": {
"format": "{value}",
"style": {}
},
"opposite": false,
"yAxis": 0,
"lineWidth": 1,
"gridLineColor": "#e6e6e6",
"gridLineWidth": 1,
"gridLineDashStyle": "solid",
"index": 0
}],
"tooltip": {
"enabled": true,
"followPointer": false,
"shared": false
},
"credits": {
"enabled": false
},
"series": [{
"type": "line",
"name": null,
"fillOpacity": 0,
"color": "#0077bc",
"fillColor": "#0077bc",
"opposite": false,
"yAxis": 0,
"legendIndex": 1,
"marker": {
"enabled": true
},
"dashStyle": "Solid",
"data": [{
"y": 396,
"toolTipData": "<div>Times on Air : 396</div><br/>"
},
{
"y": 468,
"toolTipData": "<div>Times on Air : 468</div><br/>"
}
],
"_symbolIndex": 0
}]
});
});
https://jsfiddle.net/fzg0evns/
Instead of using dates as x-axis categories you can add a date to point x property and define x-axis type = "datetime". Check the demo posted below.
Code:
"xAxis": {
"type": "datetime",
...
},
"series": [{
...
"data": [{
"y": 396,
"x": new Date('2019-06-10').getTime(),
"toolTipData": "<div>Times on Air : 396</div><br/>"
},
{
"y": 468,
"x": new Date('2019-06-17').getTime(),
"toolTipData": "<div>Times on Air : 468</div><br/>"
}
]
}]
Demos:
With categories, tickInterval, and tickPositions.
Without them.
API reference:
xAxis.type
https://api.highcharts.com/highcharts/series.line.data.x

Bar chart with wrong bar height

There are three data series, two of them are bar type series (Insolation Duration and Power Duration).
When I import data (from Striped Table) to the Highcharts, the bar chart height doesn't display properly.
It doesn't fit the scale of the chart's value, like this:
e.g. 2018/05/01
The Insolation value is less than the Power value, but the height of Power Duration bar chart is higher than Insolation Duration.
Here are the chart options I use:
var ChartObj =
{
type: "chart",
value:
{
"chart": { "alignTicks": false, "zoomType": "xy" },
"title": { "text": " ", "floating": false, "align": "center" },
"xAxis":
[
{
"categories": [], //PUT LABEL IN HERE
"crosshair": true, "index": 0, "isX": true
}
],
"tooltip": { "shared": true },
"legend":
{
"layout": "horizontal",
"align": "right",
"x": 0,
"verticalAlign": "top",
"y": 0,
"floating": false,
"backgroundColor": "#FFFFFF"
},
"yAxis":
[
{
"gridLineColor": "transparent",
"labels":
{
"format": "{value}",
"style": { "color": "#7cb5ec" },
"enabled": false
},
"title": { "text": null, "style": { "color": "#7cb5ec" } },
"opposite": false,
"index": 0,
},
{
"gridLineColor": "transparent",
"labels":
{
"format": "{value}",
"style": { "color": "#90ed7d" },
"enabled": false
},
"title":
{
"text": null,
"style": { "color": "#90ed7d" }
},
"opposite": true,
"index": 1,
},
{
"gridLineColor": "transparent",
"labels":
{
"format": "{value}",
"style": { "color": "#f7a35c" },
"enabled": false
},
"title": { "text": null,
"style": { "color": "#f7a35c" } },
"opposite": true,
"index": 2,
}
],
"series":
[
{
// Insolation
"name": " ",
"color": "#90ed7d",
"tooltip":
{
"valueSuffix": "",
"pointFormat": "<span style=\"color:{point.color}\">●</span> {series.name}: <b>{point.y:,.2f}</sup></b><br/>"
},
"yAxis": 0,
"type": "column",
"data": [],
"_symbolIndex": 0
},
{
// Power
"name": " ",
"color": "#f7a35c",
"tooltip":
{
"valueSuffix": "",
"pointFormat": "<span style=\"color:{point.color}\">●</span> {series.name}: <b>{point.y:,.2f}</b><br/>"
},
"yAxis": 1,
"type": "column",
"data": [],
"_symbolIndex": 1
},
{
// PR
"name": " ",
"color": "#7cb5ec",
"tooltip":
{
"valueSuffix": "",
"pointFormat": "<span style=\"color:{point.color}\">●</span> {series.name}: <b>{point.y:,.2f}</b><br/>"
},
"yAxis": 2,
"type": "line",
"data": []
}
]
}
};
You will need to set a max to the 2 first column axis like this
{
"gridLineColor": "transparent",
"labels":
{
"format": "{value}",
"style": { "color": "#7cb5ec" },
"enabled": false
},
"title": { "text": null, "style": { "color": "#7cb5ec" } },
"opposite": false,
"index": 0,
max:12 // The value to set
},
Or change the index of your series to use the same yAxis
Demo Fiddle

Resources