Align titles for multiple axis in Highstock - highcharts

I have 4 axis in a Highstock chart:
var p0 = [
[1538341200000,110.91],
[1538427600000,126.01],
[1538514000000,129.54],
[1538600400000,125.54]];
var p1 = [
[1538341200000,113.14],
[1538427600000,129.48],
[1538514000000,132.28],
[1538600400000,129.53],];
var t0 = [
[1538341200000,29.25],
[1538427600000,37.28],
[1538514000000,36.1],
[1538600400000,36.17],];
var t1 = [
[1538341200000,29.67],
[1538427600000,37.53],
[1538514000000,37.26],
[1538600400000,37.9],];
Highcharts.stockChart('container', {
chart: {
renderTo: "container"
},
title: {
text: "Sample test",
align: "center",
y: 14
},
legend: {
enabled: true,
align: "center",
verticalAlign: "top",
y: 40
},
xAxis: {
ordinal: false
},
yAxis: [
{
left: "-100%",
height: "18%",
top: "7%"
},
{
left: "-100%",
height: "18%",
top: "32%"
},
{
left: "-100%",
height: "18%",
top: "57%"
},
{
left: "-100%",
height: "18%",
top: "82%"
}
],
series: [
{
name: "Pressure 3",
data: p0,
yAxis: 0
},
{
name: "Pressure 4",
data: p1,
yAxis: 1
},
{
name: "Temperature 3",
data: t0,
yAxis: 2
},
{
name: "Temperature 4",
data: t1,
yAxis: 3
}
]
});
<script src="http://code.highcharts.com/stock/highstock.js"></script>
<div id="container" style="width: 600px; height: 600px;"></div>
Now, I want to add titles to every axis on the top left corner, like this:
var p0 = [
[1538341200000,110.91],
[1538427600000,126.01],
[1538514000000,129.54],
[1538600400000,125.54]];
var p1 = [
[1538341200000,113.14],
[1538427600000,129.48],
[1538514000000,132.28],
[1538600400000,129.53],];
var t0 = [
[1538341200000,29.25],
[1538427600000,37.28],
[1538514000000,36.1],
[1538600400000,36.17],];
var t1 = [
[1538341200000,29.67],
[1538427600000,37.53],
[1538514000000,37.26],
[1538600400000,37.9],];
Highcharts.stockChart('container', {
chart: {
renderTo: "container"
},
title: {
text: "Sample test",
align: "center",
y: 14
},
legend: {
enabled: true,
align: "center",
verticalAlign: "top",
y: 40
},
xAxis: {
ordinal: false
},
yAxis: [
{
title: {
text: "Pressure 3",
rotation: 0,
y: -10
},
left: "-101%",
height: "18%",
top: "7%"
},
{
title: {
text: "Pressure 4",
rotation: 0,
y: -10
},
left: "-101%",
height: "18%",
top: "32%"
},
{
title: {
text: "Temperature 3",
rotation: 0,
y: -10
},
left: "-101%",
height: "18%",
top: "57%"
},
{
title: {
text: "Temperature 4",
rotation: 0,
y: -10
},
left: "-101%",
height: "18%",
top: "82%"
}
],
series: [
{
name: "Pressure 3",
data: p0,
yAxis: 0
},
{
name: "Pressure 4",
data: p1,
yAxis: 1
},
{
name: "Temperature 3",
data: t0,
yAxis: 2
},
{
name: "Temperature 4",
data: t1,
yAxis: 3
}
]
});
<script src="http://code.highcharts.com/stock/highstock.js"></script>
<div id="container" style="min-width: 400px; height: 600px;"></div>
As you can see every title breaks the next one adding some margin and "pushing" them to the right.
This is the expected result:
I tried many highstock properties and css styles to make them float to avoid them to push themselves, but nothing is working.
How to avoid this problem?

What you're trying to achieve is not a default behavior for axis title. The easiest way to plot titles as you expect is to make custom titles using Highcharts SVG renderer.
Each yAxis has properties top and left that we can use to plot custom titles at proper positions. Notice, that navigator is just an additional series so yAxis array will have one more element than you defined. Titles created by renderer are Highcharts.SVGElement. Each time the chart will be rendered you have to destroy the old ones and rendered them again (in new positions):
var titlesColl = [],
titles = [
"Pressure 3",
"Pressure 4",
"Temperature 3",
"Temperature 4"
];
chart: {
events: {
render: function() {
var chart = this,
yaxisColl = chart.yAxis,
offsetY = -4,
axis,
title,
i;
if (titlesColl.length) {
titlesColl.forEach(function(elem) {
elem.destroy();
});
titlesColl.length = 0;
}
for (i = 0; i < yaxisColl.length - 1; i++) {
axis = yaxisColl[i];
title = chart.renderer
.text(titles[i], axis.left, axis.top + offsetY)
.css({
'font-size': '10px'
})
.add();
titlesColl.push(title);
}
}
}
}
chart.events.render documentation
Demo:
https://jsfiddle.net/wchmiel/sxnyLhfb/

Related

Set yAxis background color in Highstock

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/

Built linear gauge with highcharts (with pointer)

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

Highcharts - How to deploy data labels & tooltips for 2nd data series

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.

highstock: PlotlLines text legend does not work when having 2 x-axes

I have 2 x-axes in a chart and would like to plot 2 y-axes lines. However, the text legend of the plotted lines in the y-axes are printed on top of the chart and not right to the plotlines.
Here's a fiddle:
http://jsfiddle.net/joe992005/s48gV/
$(function() {
var seriesOptions = [],
yAxisOptions = [],
seriesCounter = 0,
names = ['MSFT', 'AAPL', 'GOOG'],
colors = Highcharts.getOptions().colors;
$.each(names, function(i, name) {
$.getJSON('http://www.highcharts.com/samples/data/jsonp.php?filename='+ name.toLowerCase() +'-c.json&callback=?', function(data) {
seriesOptions[i] = {
name: name,
data: data
};
seriesCounter++;
if (seriesCounter == names.length) {
createChart();
}
});
});
function createChart() {
window.chart = new Highcharts.StockChart({
chart: {
renderTo : 'container',
},
yAxis: [{
plotLines: [{
value: 0,
width: 2,
color: 'silver'
},{
value : 600,
color : 'green',
dashStyle : 'shortdash',
width : 2,
label : {
align: 'right',
y: 12,
x: 0,
text : 'test bla bla bla 1'
}
}, {
value : 250,
color : 'red',
dashStyle : 'shortdash',
width : 2,
label : {
align: 'left',
y: 12,
x: 0,
text : 'test bla bla bla 2'
}
}]
}],
xAxis: [{
}, {
linkedTo: 0
}],
series: seriesOptions
});
}
});
Can anybody help me on on that?
It looks like a bug, reported to our developers here: https://github.com/highslide-software/highcharts.com/issues/3000

Two pies, one legend with unique items (merge legends)

Is it possible to do two pies in one graphic and merge legends?
I did this : http://jsfiddle.net/Adysone/YpfBs/
chart = new Highcharts.Chart({
chart: {
renderTo: 'container',
type: 'pie'
},
title: {
text: "Pie Charts",
align: 'center'
},
legend: {
layout: 'vertical',
align: 'right',
verticalAlign: 'top'
},
tooltip: {
formatter: function () {
return this.key + ': ' + this.y + ' (' + Math.round(this.percentage) + '%)';
}
},
plotOptions: {
pie: {
showInLegend: true,
size: 200
}
},
series: [
{
name: "2011",
data: [
{
name: "Apple",
color: "#FF3333",
y: 8
},
{
name: "Banana",
color: "#FFF55C",
y: 11
},
{
name: "Grape",
color: "#90007B",
y: 9
},
{
name: "Pear",
color: "#F1FFB8",
y: 3
}
],
center: [150,100],
size: 150
},
{
name: "2012",
data: [
{
name: "Apple",
color: "#FF3333",
y: 5
},
{
name: "Banana",
color: "#FFF55C",
y: 15
},
{
name: "Pear",
color: "#F1FFB8",
y: 8
}
],
center: [450,100],
size: 150
}
]
});
But legend items are duplicated since they are common in the two pies, how can I do to make these unique?
If it's not possible, can I make two legends separate?
Thanks!
Please take look at example http://jsfiddle.net/u7FQS/15/ which used 3 pie charts and has common legend
$(chart.series[0].data).each(function(i, e) {
e.legendItem.on('click', function(event) {
var legendItem=e.name;
event.stopPropagation();
$(chart.series).each(function(j,f){
$(this.data).each(function(k,z){
if(z.name==legendItem)
{
if(z.visible)
{
z.setVisible(false);
}
else
{
z.setVisible(true);
}
}
});
});
});
});

Resources