I am trying to color Y axes on a Highstock chart, I tried changing the plotBackgroundColor but it changes the whole plot area.
2 images are more than 2 thousand words:
On the left I have my current result, it changes the whole plot area background color, so is not easy to see where a chart ends and the next one starts, On the right is the expected result, each axis is separated by the background color and a gray border.
This is my code:
var p0 = [
[1540166400000,122.85],
[1540170000000,122.33],
[1540173600000,120.96],
[1540177200000,120.77],
[1540180800000,120.84],
[1540184400000,120.61],
[1540188000000,120.83],
[1540191600000,121.04],
[1540195200000,120.67],
[1540198800000,121.05],
[1540202400000,122.29],
[1540206000000,122.45],
[1540209600000,123.13],
[1540213200000,123.74],
[1540216800000,124.07],
[1540224000000,123.28],
[1540227600000,122.59],
[1540231200000,122.98],
[1540234800000,123.51],
[1540238400000,123.38],
[1540242000000,123.45],
[1540245600000,123.15],
[1540249200000,123.72],
[1540252800000,123.65],
[1540256400000,123.65],
[1540260000000,123.28],
[1540263600000,122.56],
[1540267200000,122.41],
[1540270800000,122.23],
[1540274400000,122.22],
[1540278000000,122.4],
[1540281600000,121.57],
[1540285200000,121.69],
[1540288800000,121.98]];
var p1 = [
[1540166400000,127.27],
[1540170000000,126.74],
[1540173600000,125.46],
[1540177200000,125.49],
[1540180800000,125.71],
[1540184400000,125.49],
[1540188000000,125.57],
[1540191600000,126.02],
[1540195200000,125.62],
[1540198800000,125.88],
[1540202400000,126.49],
[1540206000000,127.11],
[1540209600000,127.97],
[1540213200000,128.84],
[1540216800000,128.66],
[1540224000000,127.63],
[1540227600000,126.98],
[1540231200000,127.63],
[1540234800000,127.77],
[1540238400000,127.21],
[1540242000000,127.24],
[1540245600000,126.87],
[1540249200000,126.99],
[1540252800000,127.04],
[1540256400000,127.47],
[1540260000000,126.91],
[1540263600000,126.3],
[1540267200000,126.36],
[1540270800000,126.07],
[1540274400000,126.09],
[1540278000000,126.18],
[1540281600000,125.54],
[1540285200000,125.7],
[1540288800000,126.06]];
chart = new Highcharts.StockChart({
chart: {
renderTo: "container",
backgroundColor:'#EBEBEB',
plotBackgroundColor:'#FFFFFF',
plotBorderColor: '#999999',
plotBorderWidth: 2
},
title: {
text: "Coloring axis",
},
legend: {
enabled: false
},
xAxis: {
ordinal: false
},
yAxis: [
{
minorTicks: 1,
height: "46%",
top: "4%"
},
{
minorTicks: 1,
height: "46%",
top: "54%"
}
],
series: [
{
name: "Val1 1",
data: p0,
yAxis: 0,
},
{
name: "Presión 2",
data: p1,
yAxis: 1,
},
]
});
<script src="http://code.highcharts.com/stock/highstock.js"></script>
<div id="container" style="width: 600px; height: 600px;"></div>
A workaround to achieve what you are after can be done by using a third yAxis, like this:
{
height: "4%",
top: "50%",
labels: {
enabled: false
},
min: 0,
max: 1,
minorGridLineWidth: 0,
gridLineWidth: 0,
plotBands: [{
color: '#EBEBEB',
borderColor:'#999999',
borderWidth: 2,
from: 0.05,
to: 0.95,
}
}
var p0 = [
[1540166400000,122.85],
[1540170000000,122.33],
[1540173600000,120.96],
[1540177200000,120.77],
[1540180800000,120.84],
[1540184400000,120.61],
[1540188000000,120.83],
[1540191600000,121.04],
[1540195200000,120.67],
[1540198800000,121.05],
[1540202400000,122.29],
[1540206000000,122.45],
[1540209600000,123.13],
[1540213200000,123.74],
[1540216800000,124.07],
[1540224000000,123.28],
[1540227600000,122.59],
[1540231200000,122.98],
[1540234800000,123.51],
[1540238400000,123.38],
[1540242000000,123.45],
[1540245600000,123.15],
[1540249200000,123.72],
[1540252800000,123.65],
[1540256400000,123.65],
[1540260000000,123.28],
[1540263600000,122.56],
[1540267200000,122.41],
[1540270800000,122.23],
[1540274400000,122.22],
[1540278000000,122.4],
[1540281600000,121.57],
[1540285200000,121.69],
[1540288800000,121.98]];
var p1 = [
[1540166400000,127.27],
[1540170000000,126.74],
[1540173600000,125.46],
[1540177200000,125.49],
[1540180800000,125.71],
[1540184400000,125.49],
[1540188000000,125.57],
[1540191600000,126.02],
[1540195200000,125.62],
[1540198800000,125.88],
[1540202400000,126.49],
[1540206000000,127.11],
[1540209600000,127.97],
[1540213200000,128.84],
[1540216800000,128.66],
[1540224000000,127.63],
[1540227600000,126.98],
[1540231200000,127.63],
[1540234800000,127.77],
[1540238400000,127.21],
[1540242000000,127.24],
[1540245600000,126.87],
[1540249200000,126.99],
[1540252800000,127.04],
[1540256400000,127.47],
[1540260000000,126.91],
[1540263600000,126.3],
[1540267200000,126.36],
[1540270800000,126.07],
[1540274400000,126.09],
[1540278000000,126.18],
[1540281600000,125.54],
[1540285200000,125.7],
[1540288800000,126.06]];
chart = new Highcharts.StockChart({
chart: {
renderTo: "container",
backgroundColor:'#EBEBEB',
plotBackgroundColor:'#FFFFFF',
plotBorderColor: '#999999',
plotBorderWidth: 2
},
title: {
text: "Coloring axis",
},
legend: {
enabled: false
},
xAxis: {
ordinal: false
},
yAxis: [
{
minorTicks: 1,
height: "46%",
top: "4%",
plotLines: [
]
},
{
minorTicks: 1,
height: "46%",
top: "54%",
plotLines: [
]
},
{
height: "4%",
top: "50%",
labels: {
enabled: false
},
min: 0,
max: 1,
minorGridLineWidth: 0,
gridLineWidth: 0,
plotBands: [{
color: '#EBEBEB',
borderColor:'#999999',
borderWidth: 2,
from: 0.05,
to: 0.95,
}]
}
],
series: [
{
name: "Val1 1",
data: p0,
yAxis: 0,
},
{
name: "Presión 2",
data: p1,
yAxis: 1,
},
]
});
<script src="https://code.highcharts.com/stock/highstock.js"></script>
<div id="container" style="width: 600px; height: 600px;"></div>
JSFiddle example: https://jsfiddle.net/ewolden/q826ze9v/8/
The "correct" way to achieve what you are after would be to follow highcharts' syncronized chart example: https://www.highcharts.com/demo/synchronized-charts. This is more complicated, but allows you much more customization, and would probably prove easier to work with long term.
I finally did it using highcharts SVGRenderer, drawing white rectangles for each axis at z-index:-1 to draw it on the background.
I hope this helps someone!
var p0 = [
[1540166400000,122.85],
[1540170000000,122.33],
[1540173600000,120.96],
[1540177200000,120.77],
[1540180800000,120.84],
[1540184400000,120.61],
[1540188000000,120.83],
[1540191600000,121.04],
[1540195200000,120.67],
[1540198800000,121.05],
[1540202400000,122.29],
[1540206000000,122.45],
[1540209600000,123.13],
[1540213200000,123.74],
[1540216800000,124.07],
[1540224000000,123.28],
[1540227600000,122.59],
[1540231200000,122.98],
[1540234800000,123.51],
[1540238400000,123.38],
[1540242000000,123.45],
[1540245600000,123.15],
[1540249200000,123.72],
[1540252800000,123.65],
[1540256400000,123.65],
[1540260000000,123.28],
[1540263600000,122.56],
[1540267200000,122.41],
[1540270800000,122.23],
[1540274400000,122.22],
[1540278000000,122.4],
[1540281600000,121.57],
[1540285200000,121.69],
[1540288800000,121.98]];
var p1 = [
[1540166400000,127.27],
[1540170000000,126.74],
[1540173600000,125.46],
[1540177200000,125.49],
[1540180800000,125.71],
[1540184400000,125.49],
[1540188000000,125.57],
[1540191600000,126.02],
[1540195200000,125.62],
[1540198800000,125.88],
[1540202400000,126.49],
[1540206000000,127.11],
[1540209600000,127.97],
[1540213200000,128.84],
[1540216800000,128.66],
[1540224000000,127.63],
[1540227600000,126.98],
[1540231200000,127.63],
[1540234800000,127.77],
[1540238400000,127.21],
[1540242000000,127.24],
[1540245600000,126.87],
[1540249200000,126.99],
[1540252800000,127.04],
[1540256400000,127.47],
[1540260000000,126.91],
[1540263600000,126.3],
[1540267200000,126.36],
[1540270800000,126.07],
[1540274400000,126.09],
[1540278000000,126.18],
[1540281600000,125.54],
[1540285200000,125.7],
[1540288800000,126.06]];
chart = new Highcharts.StockChart({
chart: {
renderTo: "container",
backgroundColor:'#EBEBEB'
},
title: {
text: "Coloring axis",
},
legend: {
enabled: false
},
xAxis: {
ordinal: false
},
yAxis: [
{
minorTicks: 1,
height: "46%",
top: "4%"
},
{
minorTicks: 1,
height: "46%",
top: "54%"
}
],
series: [
{
name: "Val1 1",
data: p0,
yAxis: 0,
},
{
name: "Presión 2",
data: p1,
yAxis: 1,
},
]
}, function (chart) { // on complete
var yaxisColl = chart.yAxis;
for(f=0;f<yaxisColl.length;f++){
axis = yaxisColl[f];
chart.renderer.rect(10, axis.top, axis.width, axis.height, 0, 2)
.attr({
'stroke-width': 2,
stroke: '#999999',
fill: '#FFFFFF',
zIndex: -1
})
.add();
}
});
<script src="http://code.highcharts.com/stock/highstock.js"></script>
<div id="container" style="width: 600px; height: 600px;"></div>
You could also do it using plotBands on each yAxis:
yAxis: [
{
minorTicks: 1,
height: "46%",
top: "4%",
plotBands: [{
from:-1000,
to:1000,
color:'rgb(255,255,255)'
}]
},
{
minorTicks: 1,
height: "46%",
top: "54%",
plotBands: [{
from:-1000,
to:1000,
color:'rgb(255,255,255)'
}]
}
]
Example: http://jsfiddle.net/jlbriggs/k2syL51r/
I'm trying to recreate a linear gauge chart of fusionchart in highcharts. This is the example that I am trying to recreate.
Head:
<script type="text/javascript" src="https://static.fusioncharts.com/code/latest/fusioncharts.js"></script>
<script type="text/javascript" src="https://static.fusioncharts.com/code/latest/fusioncharts.charts.js"></script>
<script type="text/javascript" src="https://static.fusioncharts.com/code/latest/fusioncharts.widgets.js"></script>
<script type="text/javascript" src="https://static.fusioncharts.com/code/latest/themes/fusioncharts.theme.fint.js"></script>
<div id="chart-container">FusionCharts will render here</div>
Body:
FusionCharts.ready(function () {
var cpuGauge = new FusionCharts({
type: 'hlineargauge',
renderAt: 'chart-container',
id: 'cpu-linear-gauge',
width: '400',
height: '190',
dataFormat: 'json',
dataSource: {
"chart": {
"theme": "fint",
"lowerLimit": "-1.9",
"upperLimit": "4.4",
"numberSuffix": "%",
"chartBottomMargin": "40",
"valueFontSize": "11",
"pointerBgColor": "#000000",
"baseFontColor": "#000000",
"decimalSeparator": ",",
"forceDecimals": "1",
"decimals": "1",
"valueFontBold": "0"
},
"colorRange": {
"color": [
{
"minValue": "-1.9",
"maxValue": "-0.1",
"label": "",
"code": "#e51b1b",
},
{
"minValue": "-0.1",
"maxValue": "1.0",
"label": "",
"code": "#fa7921",
},
{
"minValue": "1.0",
"maxValue": "1.5",
"label": "",
"code": "#fde74c",
},
{
"minValue": "1.5",
"maxValue": "4.4",
"label": "",
"code": "#9bc53d",
}
]
},
"pointers": {
"pointer": [
{
"value": "2"
}
]
},
}
})
.render();
});
The highcharts chart must take over the following properties:
Negative values
At least 4 groups (colors)
Pointer (indication marker) with number at top
In addition, I would really appreciate if there is an animation where you can see the pointer moving.
The bullet graph from highcharts comes closest to the fusionchart. I have made a first step (example) with this graph
Head:
<script src="https://code.highcharts.com/highcharts.js"></script>
<script src="https://code.highcharts.com/modules/bullet.js"></script>
<div id="container1"></div>
Body:
Highcharts.setOptions({
chart: {
inverted: true,
marginLeft: 135,
type: 'bullet'
},
title: {
text: null
},
legend: {
enabled: false
},
yAxis: {
gridLineWidth: 0
},
plotOptions: {
series: {
pointPadding: 0.25,
borderWidth: 0,
color: '#000',
targetOptions: {
width: '200%'
}
}
},
credits: {
enabled: false
},
exporting: {
enabled: false
}
});
Highcharts.chart('container1', {
chart: {
marginTop: 40
},
title: {
text: ''
},
xAxis: {
categories: "P"
},
yAxis: {
plotBands: [{
from: -1.9,
to: -0.1,
color: '#e51b1b'
}, {
from: -0.1,
to: 1,
color: '#fa7921'
}, {
from: 1,
to: 1.5,
color: '#fde74c'
}, {
from: 1.5,
to: 4.4,
color: '#9bc53d'
}],
labels: {
format: '{value}%'
},
title: null
},
series: [{
data: [{
y: 0,
target: 2
}]
}],
tooltip: {
pointFormat: '<b>{point.y}</b> (with target at {point.target})'
}
});
CSS:
#container1 {
max-width: 800px;
height: 115px;
margin: 1em auto;
}
But encounter a number of problems:
Negative numbers are not working
Pointer
Maximum is not shown (stops before 4.4)
With reference to this post. I have modified this chart with yAxis.tickPositioner and min, max property of yAxis
$(function () {
/**
* Highcharts Linear-Gauge series plugin
*/
(function (H) {
var defaultPlotOptions = H.getOptions().plotOptions,
columnType = H.seriesTypes.column,
wrap = H.wrap,
each = H.each;
defaultPlotOptions.lineargauge = H.merge(defaultPlotOptions.column, {});
H.seriesTypes.lineargauge = H.extendClass(columnType, {
type: 'lineargauge',
//inverted: true,
setVisible: function () {
columnType.prototype.setVisible.apply(this, arguments);
if (this.markLine) {
this.markLine[this.visible ? 'show' : 'hide']();
}
},
drawPoints: function () {
// Draw the Column like always
columnType.prototype.drawPoints.apply(this, arguments);
// Add a Marker
var series = this,
chart = this.chart,
inverted = chart.inverted,
xAxis = this.xAxis,
yAxis = this.yAxis,
point = this.points[0], // we know there is only 1 point
markLine = this.markLine,
ani = markLine ? 'animate' : 'attr';
// Hide column
point.graphic.hide();
if (!markLine) {
var path = inverted ? ['M', 0, 0, 'L', -5, -5, 'L', 5, -5, 'L', 0, 0, 'L', 0, 0 + xAxis.len] : ['M', 0, 0, 'L', -5, -5, 'L', -5, 5,'L', 0, 0, 'L', xAxis.len, 0];
markLine = this.markLine = chart.renderer.path(path)
.attr({
fill: series.color,
stroke: series.color,
'stroke-width': 1
}).add();
}
markLine[ani]({
translateX: inverted ? xAxis.left + yAxis.translate(point.y) : xAxis.left,
translateY: inverted ? xAxis.top : yAxis.top + yAxis.len - yAxis.translate(point.y)
});
}
});
})(Highcharts);
$('#container').highcharts({
chart: {
type: 'lineargauge',
inverted: true
},
title: {
text: 'A Horizontal Linear Gauge'
},
xAxis: {
lineColor: '#C0C0C0',
labels: {
enabled: false
},
tickLength: 0,
},
yAxis: {
min: -1.9,
max: 4.4,
tickPositions: [-1.9, -0.1,1,1.5 ,4.4],
tickLength: 1,
tickWidth: 1,
tickColor: '#C0C0C0',
gridLineColor: '#C0C0C0',
gridLineWidth: 1,
minorTickInterval: 5,
minorTickWidth: 1,
minorTickLength: 5,
minorGridLineWidth: 0,
startOnTick: true,
endOnTick: true,
title: null,
labels: {
format: '{value}%'
},
plotBands: [{
from:-1.9,
to: -0.1,
color: 'rgba(229, 27, 27, 1)'
}, {
from: -0.1,
to: 1.0,
color: 'rgba(250, 121, 33, 1)'
}, {
from: 1.0,
to: 1.5,
color: 'rgba(253, 231, 76, 1)'
},
{
from: 1.5,
to: 4.4,
color: 'rgba(155, 197, 61, 1)'
}]
},
legend: {
enabled: false
},
series: [{
data: [1.1],
color: '#000000',
dataLabels: {
enabled: true,
align: 'center',
format: '{point.y}%',
y: 10,
}
}]
}, // Add some life
function (chart) {
setInterval(function () {
Highcharts.each(chart.series, function (serie) {
var point = serie.points[0],
newVal,
inc = (Math.random() - 0.5) *10;
newVal = point.y + inc;
if (newVal < -1.9 || newVal > 4.4) {
newVal = point.y - inc;
}
point.update(Math.floor(newVal));
});
}, 2000);
});
});
Fiddle demo
I've created a Highcharts that is a bit unusual. It's placing two series in the same plotarea, but instead of them "lining up" and sharing the entire plot area, series0 is using the left side of the area and series1 is using the right side. Everything is working great except for two (related) things: I cannot get tooltips or datalabels to display for the series1 data on the right-hand side of the page. Completely guessing here, but I'm guessing the series are not being shared because they are not lining up together.
I've spent the past day trying various things and have completely ran out of ideas. Hoping a fresh set of eyes might spot something that will work. Attached is a fiddle for your viewing pleasure...
https://jsfiddle.net/wk0uh72o/
<script src="https://code.highcharts.com/highcharts.js"></script>
<script src="https://code.highcharts.com/highcharts-more.js"></script>
<script src="https://code.highcharts.com/modules/exporting.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script>
<div id="adaRate"></div>
$(function() {
var options = {
chart: {
renderTo: 'adaRate',
type: 'bar',
width: 600,
height: 400
},
title: {
text: 'Average Daily Attendance Rate',
align: 'center',
style: {
fontWeight: 'bold',
color: 'rgba(0,0,0,.9)'
}
},
legend: {
enabled: true
},
tooltip: {
shared: true,
crosshairs: true,
formatter: function() {
var s = '<b>' + this.x + '</b>';
$.each(this.points, function() {
s += '<br/>' + this.series.name + ': ' +
this.y + '%';
});
return s;
},
},
xAxis: {
labels: {
style: {
fontWeight: 'bold'
}
}
},
yAxis: [{
min: 0,
max: 100,
opposite: true,
width: 270,
title: {
text: 'Average Daily Attendance %'
}
}, {
min: -10,
max: 10,
offset: 0,
opposite: true,
plotLines: [{
color: 'red',
value: 0,
width: 2
}],
left: 400,
width: 170,
title: {
text: 'Variance from Prior Year'
}
}],
series: [{
name: 'ADA',
dataLabels: {
enabled: true,
align: 'right',
color: '#FFFFFF',
x: -10
},
yAxis: 0,
}, {
type: 'scatter',
name: 'PY Variance',
dataLabels: {
enabled: true,
align: 'center',
color: '#000000',
x: -10
},
yAxis: 1,
}],
credits: {
enabled: false
}
};
var categories = ["School 1", "School 2", "School 3", "School 4", "School 5", "School 6", "School 7"];
var adaRate = [96.4, 95.9, 93.3, 92.3, 89.8, 85.4, 83.9];
var adaVar = [{
"color": "yellow",
"y": -.8
}, {
"color": "red",
"y": -3.5
}, {
"color": "lightgreen",
"y": 1.5
}, {
"color": "lightgreen",
"y": 2.3
}, {
"color": "red",
"y": -4.3
}, {
"color": "green",
"y": 5.3
}, {
"color": "darkgreen",
"y": 7.8
}
];
options.xAxis.categories = categories;
options.series[0].data = adaRate;
options.series[1].data = adaVar;
var chart = new Highcharts.Chart(options);
});
I don't have time to write a longer answer. But, shared tooltips don't work for unordered data (pie, scatter, flag). See http://api.highcharts.com/highcharts#tooltip.shared
You can simulate a scatter series using a line series with lineWidth of 0. You also have to modify the mouseOver event to not increase the lineWidth on hover.
Just need to remove tooltip on the top level. But set it in each series separately.
series: [{
name: 'ADA',
dataLabels: {
enabled: true,
align: 'right',
color: '#FFFFFF',
x: -10
},
yAxis: 0,
tooltip: {
pointFormat: 'First {point.y}'
}
}, {
type: 'scatter',
name: 'PY Variance',
dataLabels: {
enabled: true,
align: 'center',
color: '#000000',
x: -10
},
yAxis: 1,
tooltip: {
pointFormat: 'Second {point.y}'
}
}],
refer to fiddle I updated from yours.