Show Highcharts tooltip outside SVG container - highcharts

Is there a way to how the Highcharts tooltip outside the SVG container and always above the mouse?
Right now tooltips are sometimes shown over the data, because it doesn't fit within the container above the data point.

Great! I found one example which seems to work in jsfiddle: http://jsfiddle.net/vbddw4r0
$(function () {
var chart;
$(document).ready(function () {
chart = new Highcharts.Chart({
chart: {
renderTo: 'container',
type: 'line'
},
xAxis: {
type: 'datetime'
},
yAxis: {
title: {
text: 'Temperature (°C)'
},
min: 0
},
tooltip: {
enabled: true,
backgroundColor: "rgba(255,255,255,0)",
borderWidth: 0,
shadow: false,
useHTML: true,
formatter: function () {
return '<div class="tooltip"><b>' + this.series.name + '</b>' +
'<br/>' + Highcharts.dateFormat('%b %e, %H:%M', this.x) + ': ' + this.y + '<br/>' + Highcharts.dateFormat('%b %e, %H:%M', this.x) + ': ' + this.y + '<br/>' + Highcharts.dateFormat('%b %e, %H:%M', this.x) + ': ' + this.y + '<br/>' + Highcharts.dateFormat('%b %e, %H:%M', this.x) + ': ' + this.y + '<br/>' + Highcharts.dateFormat('%b %e, %H:%M', this.x) + ': ' + this.y + '<br/>' + Highcharts.dateFormat('%b %e, %H:%M', this.x) + ': ' + this.y + '<br/>' + Highcharts.dateFormat('%b %e, %H:%M', this.x) + ': ' + this.y + '<br/>' + Highcharts.dateFormat('%b %e, %H:%M', this.x) + ': ' + this.y + '<br/>' + Highcharts.dateFormat('%b %e, %H:%M', this.x) + ': ' + this.y + '</div>';
}
},
plotOptions: {
line: {
dataLabels: {
enabled: true
},
enableMouseTracking: false
}
},
series: [{
type: 'spline',
id: 'Total',
name: 'Total',
color: '#2788F4',
data: [{
id: 'Total-1361059200000',
x: 1361059200000,
y: 35.0,
marker: {
enabled: true
}
}, {
id: 'Total-1361088000000',
x: 1361088000000,
y: 254.0,
marker: {
enabled: true
}
}, {
id: 'Total-1361116800000',
x: 1361116800000,
y: 96.0,
marker: {
enabled: true
}
}, {
id: 'Total-1361145600000',
x: 1361145600000,
y: 0.0,
marker: {
enabled: false
}
}, {
id: 'Total-1361174400000',
x: 1361174400000,
y: 40.0,
marker: {
enabled: true
}
}, {
id: 'Total-1361203200000',
x: 1361203200000,
y: 117.0,
marker: {
enabled: true
}
}, {
id: 'Total-1361232000000',
x: 1361232000000,
y: 10.0,
marker: {
enabled: true
}
}, {
id: 'Total-1361260800000',
x: 1361260800000,
y: 206.0,
marker: {
enabled: true
}
}, {
id: 'Total-1361289600000',
x: 1361289600000,
y: 351.0,
marker: {
enabled: true
}
}, {
id: 'Total-1361318400000',
x: 1361318400000,
y: 0.0,
marker: {
enabled: false
}
}, {
id: 'Total-1361347200000',
x: 1361347200000,
y: 186.0,
marker: {
enabled: true
}
}, {
id: 'Total-1361376000000',
x: 1361376000000,
y: 59.0,
marker: {
enabled: true
}
}, {
id: 'Total-1361404800000',
x: 1361404800000,
y: 0.0,
marker: {
enabled: false
}
}, {
id: 'Total-1361433600000',
x: 1361433600000,
y: 211.0,
marker: {
enabled: true
}
}, {
id: 'Total-1361462400000',
x: 1361462400000,
y: 104.0,
marker: {
enabled: true
}
}, {
id: 'Total-1361491200000',
x: 1361491200000,
y: 0.0,
marker: {
enabled: false
}
}, {
id: 'Total-1361520000000',
x: 1361520000000,
y: 0.0,
marker: {
enabled: false
}
}, {
id: 'Total-1361548800000',
x: 1361548800000,
y: 0.0,
marker: {
enabled: false
}
}, {
id: 'Total-1361577600000',
x: 1361577600000,
y: 24.0,
marker: {
enabled: true
}
}, {
id: 'Total-1361606400000',
x: 1361606400000,
y: 0.0,
marker: {
enabled: false
}
}, {
id: 'Total-1361635200000',
x: 1361635200000,
y: 108.0,
marker: {
enabled: true
}
}, {
id: 'Total-1361664000000',
x: 1361664000000,
y: 0.0,
marker: {
enabled: false
}
}, {
id: 'Total-1361692800000',
x: 1361692800000,
y: 0.0,
marker: {
enabled: false
}
}]
}, {
type: 'spline',
name: 'Transparent',
color: 'rgba(255, 255, 255, 0.1)',
data: [{
x: 1361059200000,
y: 0.0,
marker: {
symbol: "square",
radius: 3,
fillColor: "#f2a8a8",
states: {
hover: {
radius: 3,
fillColor: "#f2a8a8"
}
}
}
}, {
x: 1361088000000,
y: 0.0,
marker: {
symbol: "square",
radius: 8,
fillColor: "#f2a8a8",
states: {
hover: {
radius: 8,
fillColor: "#f2a8a8"
}
}
}
}, {
x: 1361116800000,
y: 0.0,
marker: {
symbol: "square",
radius: 6,
fillColor: "#f2a8a8",
states: {
hover: {
radius: 6,
fillColor: "#f2a8a8"
}
}
}
}]
}]
});
});
});

Related

Highcharts yaxis negative values error

I am using HighCharts to ploot some graph. I want my y-aixs to range between -1 to +1. When i set max=1 and min=-1 for y-axis, it does not work. Is there another way of implementing this. Below is the my code example.
$(opts.containerSelector).find('.chart-container').highcharts({
chart: {
events: {
load: loadLegendSelection
},
},
plotOptions: {
area: {
fillOpacity: 0.7
},
spline: {
marker: {
radius: 3
}
},
series: {
events: {
legendItemClick: storeLegendSelection
}
}
},
legend: {
},
loading: {
labelStyle: { "position": "relative", "top": "45%", "font-weight": "300", "color": "#29303a", "font-size": "22px" }
},
xAxis: {
gridLineDashStyle: 'dash',
gridLineColor: '#c2dce6',
gridLineWidth: 1,
min: minDate,
max: maxDate,
type: 'datetime',
labels: {
formatter: function() {
return formatTimestampTime(this.value);
}
},
events : {
afterSetExtremes : afterSetExtremes.bind(this, opts)
},
minRange: 3600 // one minute
},
yAxis: {
max: 1,
min: -1,
endOnTick: false,
gridLineDashStyle: 'dash',
gridLineColor: '#c2dce6',
gridLineWidth: 1,
labels: {
formatter: function() {
return formatMegawatts(this.value);
}
},
showFirstLabel: false,
title: ''
},
series: convertedData,
exporting: {
enabled: false
},
credits: {
enabled: false
},
tooltip: {
formatter:
function() {
return '<b>' + formatTimestampDateTimeWithSeconds(this.x) + '</b><br>' + formatMegawatts(this.y) + ' ('+ this.series.name + ')';
}
}
});
you can try setting min and max as given below.
yAxis: [{
max:1,
min: -1,
allowDecimals: false,
endOnTick: false,
gridLineWidth: 0,
labels: {
style: {
color: '#767676'
}
},
offset: -10,
title: {
text: 'Inv ' + val_qty,
"textAlign": 'top',
"rotation": 0,
x: 60,
y: yaxisVal,
style: {
color: '#767676',
fontWeight: 'bold'
}
}
}, {
allowDecimals: false,
min: 0,
endOnTick: false,
gridLineWidth: 0,
title: {
text: y2axisname,
"textAlign": 'top',
"rotation": 0,
x: -75,
y: yaxisVal,
style: {
color: '#767676',
fontWeight: 'bold'
}
},
offset: -10,
labels: {
format: '{value}',
style: {
color: '#767676'
}
},
opposite: true
}],

After print chart another chart is not visible in page

I am using two instance of high chart(Highcharts.JS v4.1.6) parallel, but when i tried to print the chart using export functionality, another chart gets invisible when print command gets completed.
Chart configuration:
var chart1, chart2;
var options, options2;
options = {
title: {
text: '',
floating: true,
align: 'left',
width: 610,
style: {
fontSize: '1.4em'
}
},
chart: {
renderTo: 'content1',
type: 'bar',
marginLeft: 210,
marginTop: 80,
spacingBottom: 15,
spacingLeft: 10,
spacingRight: 10
},
credits: {
enabled: false
},
credits: {
text: 'Source: xxxx',
href: '',
position: {
align: 'right',
x: -30,
y: -3
}
},
exporting: {
buttons: {
contextButton: {
align: 'right',
x: 2,
y: 10,
text: 'Download',
verticalAlign: 'top'
}
}
},
xAxis: {
categories: [],
labels: {
step: 1,
enabled: true,
formatter: function() {
var text = this.value,
formatted = text.length > 25 ? text.substring(0, 30) : text;
return '<div class="js-ellipse" style="width:150px; overflow:hidden" title="' + text + '">' + formatted + '</div>';
},
style: {
fontSize: '12px'
}
}
},
yAxis: {
max: 100,
plotLines: [{
color: 'black',
dashStyle: 'Solid',
value: 0,
width: 2
}, {
color: 'black',
width: 2,
value: 50
}
],
title: {
text: ''
},
},
legend: {
itemStyle: {
color: '#000000',
fontWeight: ''
},
layout: 'horizontal',
align: 'center',
x: 1,
verticalAlign: 'top',
y: 35,
floating: true,
backgroundColor: '#FFFFFF',
reversed: true
},
tooltip: {
style: {
padding: 30
},
formatter: function() {
return '' +
'<strong>' + this.x + '</strong><br>' + this.series.name + ': ' + Highcharts.numberFormat(this.y, 1) + "%";
}
},
plotOptions: {
series: {
grouping: true,
pointPadding: 0,
borderWidth: 0,
dataLabels: {
enabled: true,
crop: false,
formatter: function() {
return this.y.toFixed(1);
}
}
}
},
series: [],
}
options2 = {
title: {
text: ''
},
chart: {
renderTo: 'content2',
type: 'bar',
spacingBottom: 15,
spacingLeft: 10,
spacingRight: 10,
marginTop: 80
},
credits: {
text: 'Source: xxx',
href: '',
position: {
align: 'right',
x: -30,
y: -3
}
},
exporting: {
buttons: {
contextButton: {
align: 'right',
x: 2,
y: 10,
text: 'Download',
verticalAlign: 'top'
}
}
},
xAxis: {
categories: [],
labels: {
enabled: false,
step: 1,
overflow: 'justify',
crop: false,
formatter: function() {
var text = this.value,
formatted = text.length > 25 ? text.substring(0, 30) : text;
return '<div class="js-ellipse" style="width:150px; overflow:hidden" title="' + text + '">' + formatted + '</div>';
},
style: {
fontSize: '12px'
}
}
},
yAxis: {
plotLines: [{
color: 'black',
dashStyle: 'Solid',
value: 0,
width: 2
}],
title: {
text: ''
},
},
legend: {
itemStyle: {
color: '#000000',
fontWeight: ''
},
layout: 'horizontal',
align: 'center',
x: 1,
verticalAlign: 'top',
y: 35,
floating: true,
backgroundColor: '#FFFFFF',
reversed: true
},
tooltip: {
style: {
padding: 30
},
formatter: function() {
return '' +
'<strong>' + this.x + '</strong><br>' + this.series.name + ': ' + Highcharts.numberFormat(this.y, 1) + "%";
}
},
plotOptions: {
series: {
dataLabels: {
enabled: true,
crop: false,
formatter: function() {
return this.y.toFixed(1);
}
}
}
},
series: [],
}
Before Print chart:
After Print when left side chart export print button used:
After Print when right side chart export print button used:
This will happen when print chart is used otherwise it work well.I couldn't figure out the issue.Please help me.
Thanks.
I have refer the below code that resolved my issue.
var beforePrint = function()
{
chart1 = jQuery('#content1').highcharts();
chartWidth1 = chart1.chartWidth;
chartHeight1 = chart1.chartHeight;
chart1.setSize(578,chartHeight1, false);
chart2 = jQuery('#content2').highcharts();
chartWidth2 = chart2.chartWidth;
chartHeight2 = chart2.chartHeight;
chart2.setSize(405,chartHeight2, false);
};
var afterPrint = function() {
chart1.setSize(chartWidth1,chartHeight1, false);
chart1.hasUserSize = null; // This makes chart responsive
chart2.setSize(chartWidth2,chartHeight2, false);
chart2.hasUserSize = null; // This makes chart responsive
};
if (window.matchMedia) {
var mediaQueryList = window.matchMedia('print');
mediaQueryList.addListener(function(mql) {
if (mql.matches) {
beforePrint();
} else {
afterPrint();
}
});
}
window.onbeforeprint = beforePrint;
window.onafterprint = afterPrint;

How to add another same chart but with different data?

I create chart using HighCharts and I copy some example from official site, I havesomething exactly like this jsfidle How to add on the same page another same chart with different data?
I'm looking on google and here for some example but can't find something matching my example.
$(function () {
var colors = Highcharts.getOptions().colors,
categories = ['MSIE', 'Firefox', 'Chrome', 'Safari', 'Opera'],
data = [{
y: 56.33,
color: colors[0],
drilldown: {
name: 'MSIE versions',
categories: ['MSIE 6.0', 'MSIE 7.0', 'MSIE 8.0', 'MSIE 9.0', 'MSIE 10.0', 'MSIE 11.0'],
data: [1.06, 0.5, 17.2, 8.11, 5.33, 24.13],
color: colors[0]
}
}, {
y: 10.38,
color: colors[1],
drilldown: {
name: 'Firefox versions',
categories: ['Firefox v31', 'Firefox v32', 'Firefox v33', 'Firefox v35', 'Firefox v36', 'Firefox v37', 'Firefox v38'],
data: [0.33, 0.15, 0.22, 1.27, 2.76, 2.32, 2.31, 1.02],
color: colors[1]
}
}, {
y: 24.03,
color: colors[2],
drilldown: {
name: 'Chrome versions',
categories: ['Chrome v30.0', 'Chrome v31.0', 'Chrome v32.0', 'Chrome v33.0', 'Chrome v34.0',
'Chrome v35.0', 'Chrome v36.0', 'Chrome v37.0', 'Chrome v38.0', 'Chrome v39.0', 'Chrome v40.0', 'Chrome v41.0', 'Chrome v42.0', 'Chrome v43.0'
],
data: [0.14, 1.24, 0.55, 0.19, 0.14, 0.85, 2.53, 0.38, 0.6, 2.96, 5, 4.32, 3.68, 1.45],
color: colors[2]
}
}, {
y: 4.77,
color: colors[3],
drilldown: {
name: 'Safari versions',
categories: ['Safari v5.0', 'Safari v5.1', 'Safari v6.1', 'Safari v6.2', 'Safari v7.0', 'Safari v7.1', 'Safari v8.0'],
data: [0.3, 0.42, 0.29, 0.17, 0.26, 0.77, 2.56],
color: colors[3]
}
}, {
y: 0.91,
color: colors[4],
drilldown: {
name: 'Opera versions',
categories: ['Opera v12.x', 'Opera v27', 'Opera v28', 'Opera v29'],
data: [0.34, 0.17, 0.24, 0.16],
color: colors[4]
}
}, {
y: 0.2,
color: colors[5],
drilldown: {
name: 'Proprietary or Undetectable',
categories: [],
data: [],
color: colors[5]
}
}],
browserData = [],
versionsData = [],
i,
j,
dataLen = data.length,
drillDataLen,
brightness;
// Build the data arrays
for (i = 0; i < dataLen; i += 1) {
// add browser data
browserData.push({
name: categories[i],
y: data[i].y,
color: data[i].color
});
// add version data
drillDataLen = data[i].drilldown.data.length;
for (j = 0; j < drillDataLen; j += 1) {
brightness = 0.2 - (j / drillDataLen) / 5;
versionsData.push({
name: data[i].drilldown.categories[j],
y: data[i].drilldown.data[j],
color: Highcharts.Color(data[i].color).brighten(brightness).get()
});
}
}
// Create the chart
$('#container').highcharts({
chart: {
type: 'pie'
},
title: {
text: 'Browser market share, January, 2015 to May, 2015'
},
subtitle: {
text: 'Source: netmarketshare.com'
},
yAxis: {
title: {
text: 'Total percent market share'
}
},
plotOptions: {
pie: {
shadow: false,
center: ['50%', '50%']
}
},
tooltip: {
valueSuffix: '%'
},
series: [{
name: 'Browsers',
data: browserData,
size: '60%',
dataLabels: {
formatter: function () {
return this.y > 5 ? this.point.name : null;
},
color: '#ffffff',
distance: -30
}
}, {
name: 'Versions',
data: versionsData,
size: '80%',
innerSize: '60%',
dataLabels: {
formatter: function () {
// display only if larger than 1
return this.y > 1 ? '<b>' + this.point.name + ':</b> ' + this.y + '%' : null;
}
}
}]
});
});
By setting a second container and add 3 new arrays: Data2, browserData2 and versionsData2, don't forget to add the last two arrays (browserData2 and versionsData2) to the series option in the second container:
series: [{
name: 'Browsers',
data: browserData2,
size: '60%',
dataLabels: {
formatter: function () {
return this.y > 5 ? this.point.name : null;
},
color: '#ffffff',
distance: -30
}
}, {
name: 'Versions',
data: versionsData2,
size: '80%',
innerSize: '60%',
dataLabels: {
formatter: function () {
// display only if larger than 1
return this.y > 1 ? '<b>' + this.point.name + ':</b> ' + this.y + '%' : null;
}
}
}]
Please check the following example (jsfiddle):
$(function () {
var colors = Highcharts.getOptions().colors,
categories = ['MSIE', 'Firefox', 'Chrome', 'Safari', 'Opera'],
data = [{
y: 56.33,
color: colors[0],
drilldown: {
name: 'MSIE versions',
categories: ['MSIE 6.0', 'MSIE 7.0', 'MSIE 8.0', 'MSIE 9.0', 'MSIE 10.0', 'MSIE 11.0'],
data: [1.06, 0.5, 17.2, 8.11, 5.33, 24.13],
color: colors[0]
}
}, {
y: 10.38,
color: colors[1],
drilldown: {
name: 'Firefox versions',
categories: ['Firefox v31', 'Firefox v32', 'Firefox v33', 'Firefox v35', 'Firefox v36', 'Firefox v37', 'Firefox v38'],
data: [0.33, 0.15, 0.22, 1.27, 2.76, 2.32, 2.31, 1.02],
color: colors[1]
}
}, {
y: 24.03,
color: colors[2],
drilldown: {
name: 'Chrome versions',
categories: ['Chrome v30.0', 'Chrome v31.0', 'Chrome v32.0', 'Chrome v33.0', 'Chrome v34.0',
'Chrome v35.0', 'Chrome v36.0', 'Chrome v37.0', 'Chrome v38.0', 'Chrome v39.0', 'Chrome v40.0', 'Chrome v41.0', 'Chrome v42.0', 'Chrome v43.0'
],
data: [0.14, 1.24, 0.55, 0.19, 0.14, 0.85, 2.53, 0.38, 0.6, 2.96, 5, 4.32, 3.68, 1.45],
color: colors[2]
}
}, {
y: 4.77,
color: colors[3],
drilldown: {
name: 'Safari versions',
categories: ['Safari v5.0', 'Safari v5.1', 'Safari v6.1', 'Safari v6.2', 'Safari v7.0', 'Safari v7.1', 'Safari v8.0'],
data: [0.3, 0.42, 0.29, 0.17, 0.26, 0.77, 2.56],
color: colors[3]
}
}, {
y: 0.91,
color: colors[4],
drilldown: {
name: 'Opera versions',
categories: ['Opera v12.x', 'Opera v27', 'Opera v28', 'Opera v29'],
data: [0.34, 0.17, 0.24, 0.16],
color: colors[4]
}
}, {
y: 0.2,
color: colors[5],
drilldown: {
name: 'Proprietary or Undetectable',
categories: [],
data: [],
color: colors[5]
}
}],
categories2 = ['A', 'B', 'C', 'D', 'E'],
data2 = [{
y: 56.33,
color: colors[0],
drilldown: {
name: 'MSIE versions',
categories: ['MSIE 6.0', 'MSIE 7.0', 'MSIE 8.0', 'MSIE 9.0', 'MSIE 10.0', 'MSIE 11.0'],
data: [1.06, 0.5, 17.2, 8.11, 5.33, 24.13],
color: colors[0]
}
}, {
y: 10.38,
color: colors[1],
drilldown: {
name: 'Firefox versions',
categories: ['F7', 'F6', 'F5', 'F4', 'F3', 'F2', 'F1'],
data: [0.33, 0.15, 0.22, 1.27, 2.76, 2.32, 2.31, 1.02],
color: colors[1]
}
}, {
y: 24.03,
color: colors[2],
drilldown: {
name: 'Chrome versions',
categories: ['Cn', 'Cm', 'Cj', 'Ct', 'Cb',
'Cc', 'Cf', 'Cy', 'Ct', 'Cr', 'Cr', 'Ce', 'Cw', 'Cq'
],
data: [0.14, 1.24, 0.55, 0.19, 0.14, 0.85, 2.53, 0.38, 0.6, 2.96, 5, 4.32, 3.68, 1.45],
color: colors[2]
}
}, {
y: 4.77,
color: colors[3],
drilldown: {
name: 'Safari versions',
categories: ['S7', 'S6', 'S5', 'S4', 'S3', 'S2', 'S1'],
data: [0.3, 0.42, 0.29, 0.17, 0.26, 0.77, 2.56],
color: colors[3]
}
}, {
y: 0.91,
color: colors[4],
drilldown: {
name: 'Opera versions',
categories: ['O1', 'O2', 'O3', 'O4'],
data: [0.34, 0.17, 0.24, 0.16],
color: colors[4]
}
}, {
y: 0.2,
color: colors[5],
drilldown: {
name: 'Proprietary or Undetectable',
categories: [],
data: [],
color: colors[5]
}
}],
browserData = [],
versionsData = [],
browserData2 = [],
versionsData2 = [],
i,
j,
dataLen = data.length,
dataLen2 = data2.length,
drillDataLen,
brightness;
// Build the data arrays
for (i = 0; i < dataLen; i += 1) {
// add browser data
browserData.push({
name: categories[i],
y: data[i].y,
color: data[i].color
});
// add version data
drillDataLen = data[i].drilldown.data.length;
for (j = 0; j < drillDataLen; j += 1) {
brightness = 0.2 - (j / drillDataLen) / 5;
versionsData.push({
name: data[i].drilldown.categories[j],
y: data[i].drilldown.data[j],
color: Highcharts.Color(data[i].color).brighten(brightness).get()
});
}
}
// Build the data arrays
for (i = 0; i < dataLen2; i += 1) {
// add browser data
browserData2.push({
name: categories2[i],
y: data2[i].y,
color: data2[i].color
});
// add version data
drillDataLen = data2[i].drilldown.data.length;
for (j = 0; j < drillDataLen; j += 1) {
brightness = 0.2 - (j / drillDataLen) / 5;
versionsData2.push({
name: data2[i].drilldown.categories[j],
y: data2[i].drilldown.data[j],
color: Highcharts.Color(data2[i].color).brighten(brightness).get()
});
}
}
// Create the chart
$('#container2').highcharts({
chart: {
type: 'pie'
},
title: {
text: 'Browser market share, January, 2015 to May, 2015'
},
subtitle: {
text: 'Source: netmarketshare.com'
},
yAxis: {
title: {
text: 'Total percent market share'
}
},
plotOptions: {
pie: {
shadow: false,
center: ['50%', '50%']
}
},
tooltip: {
valueSuffix: '%'
},
series: [{
name: 'Browsers',
data: browserData,
size: '60%',
dataLabels: {
formatter: function () {
return this.y > 5 ? this.point.name : null;
},
color: '#ffffff',
distance: -30
}
}, {
name: 'Versions',
data: versionsData,
size: '80%',
innerSize: '60%',
dataLabels: {
formatter: function () {
// display only if larger than 1
return this.y > 1 ? '<b>' + this.point.name + ':</b> ' + this.y + '%' : null;
}
}
}]
});
$('#container').highcharts({
chart: {
type: 'pie'
},
title: {
text: 'Second Chart'
},
subtitle: {
text: 'Source: netmarketshare.com'
},
yAxis: {
title: {
text: 'Total percent market share'
}
},
plotOptions: {
pie: {
shadow: false,
center: ['50%', '50%']
}
},
tooltip: {
valueSuffix: '%'
},
series: [{
name: 'Browsers',
data: browserData2,
size: '60%',
dataLabels: {
formatter: function () {
return this.y > 5 ? this.point.name : null;
},
color: '#ffffff',
distance: -30
}
}, {
name: 'Versions',
data: versionsData2,
size: '80%',
innerSize: '60%',
dataLabels: {
formatter: function () {
// display only if larger than 1
return this.y > 1 ? '<b>' + this.point.name + ':</b> ' + this.y + '%' : null;
}
}
}]
});
});
If you need 3 charts you can copy-paste the initialization and just change the data and container name.
Or you can make a function, that populate a chart by given data and container name. Something like this:
function populateChart(renderTo,data,title) {
var chart = new Highcharts.Chart({
chart: {
renderTo: renderTo,
type: 'column'
},
title: {
text: title
},
xAxis: {
categories: ['Apples', 'Oranges', 'Pears', 'Grapes', 'Bananas']
},
yAxis: {
allowDecimals: false,
min: 0,
title: {
text: 'Number of fruits'
}
},
tooltip: {
formatter: function () {
return '<b>' + this.x + '</b><br/>' +
this.series.name + ': ' + this.y + '<br/>' +
'Total: ' + this.point.stackTotal;
}
},
series: [{
name: 'John',
data: data,
stack: 'male'
}]
});
}
And then just call it when needed:
$(function(){
populateChart('container1',[5, 3, 4, 7, 2],'Title 1');
populateChart('container2',[3, 4, 4, 2, 5],'Title 2');
populateChart('container3',[2, 5, 6, 2, 1],'Title 3');
});
You can check my example

HighChart not showing anything

Can anyone maybe tell me what I am doing wrong here. Because my Chart shows the X values but my Y values does not plot on the chart.
Note reason for this x: and y: is because I am using dotnet highchart helper.
chart: { renderTo:'chart_0_container', backgroundColor: '#FFFFFF', className: 'chart1', defaultSeriesType: 'line', marginRight: 10, plotShadow: false, resetZoomButton: { position: { align: 'left' } }, zoomType: 'xy' },
xAxis: { allowDecimals: false, type: 'linear' },
yAxis: [{ labels: { formatter: function () {return Highcharts.numberFormat(this.value,2,'.' ,' ');} }, max: 0, title: { text: '' } }],
legend: { enabled: true },
tooltip: { enabled: true, formatter: function() { return '<span style="color:' + this.series.color + ';">●</span> ' + this.series.name + ': <b>' + Highcharts.numberFormat(this.y,',','.') + '</b><br/>' + Highcharts.dateFormat(' %Y-%m-%d %H:%M (%A)' , new Date(this.x)); } },
title: { text: '' },
plotOptions: { line: { marker: { enabled: true } } },
exporting: { enabled: true, filename: 'TrendExport' },
series: [{ data:
[{ x: 49.898418, y: 21.32 },
{ x: 49.882478, y: 21.32 },
{ x: 51.759454, y: 21.57 },
{ x: 51.385514, y: 21.56 },
{ x: 50.678916, y: 21.47 },
{ x: 50.226594, y: 21.35 },
{ x: 49.956602, y: 21.25 },
{ x: 49.841858, y: 21.24 },
{ x: 49.865894, y: 21.28 },
{ x: 49.845258, y: 21.31 },
{ x: 49.797864, y: 21.21 },
{ x: 49.880792, y: 21.29 },
{ x: 50.863658, y: 21.31 },
{ x: 50.017988, y: 21.21 },
{ x: 49.98614, y: 21.21 },
{ x: 50.105496, y: 21.29 },
{ x: 49.712604, y: 21.19 },
{ x: 49.714074, y: 21.2 },
{ x: 49.756014, y: 21.19 },
{ x: 49.817874, y: 21.23 },
{ x: 49.798772, y: 21.21 },
{ x: 50.006356, y: 21.3 },
{ x: 50.06892, y: 21.32 },
{ x: 49.77289, y: 21.21 },
{ x: 49.700852, y: 21.2 },
{ x: 49.653704, y: 21.19 },
{ x: 49.736278, y: 21.21 },
{ x: 49.757966, y: 21.21 },
{ x: 49.7942, y: 21.22 },
{ x: 49.75787, y: 21.21 }], name: 'ABSA Capital Durban Incomer (kVAr)' }]
Thanks you in advance.
Ideally you should get sorted data from back-end logic and provide that to your chart .If it can't be in sorted order do following :
Put your series data in a variable and sort the data using:
var dataToSort = [{ x: 49.898418, y: 21.32 },
{ x: 49.882478, y: 21.32 },
{ x: 51.759454, y: 21.57 },
{ x: 51.385514, y: 21.56 },
{ x: 50.678916, y: 21.47 },
{ x: 50.226594, y: 21.35 },
// .......and so on
dataToSort.sort(function(a, b) {
return parseFloat(a.x) - parseFloat(b.x);
});
Also remove the date-formatter in tooltip, Itsdoesn't seem that your data has any timestamp or UTC date in x field .
Also as mentioned by #mekhatria remove max:0
See Working fiddle here
You have max:0 in yAxis.
Fix it here :), check jsfiddle
yAxis: [{
labels: {
formatter: function() {
return Highcharts.numberFormat(this.value, 2, '.', ' ');
}
},
//max: 0,
title: {
text: ''
}
}],
legend: {
enabled: true
},

Highcharts: dynamic update stacked area with extra custom data

I want to display custom prompt info in stacked area chart using the technique referred in (jQuery Highchart) Is there any way to put extra custom data inside Tooltip Box?
The chart works fine on the initial data, but does not working when dynamic adding new Points.
The source code is in http://jsfiddle.net/ukNPz/1/
$(function () {
var clusterInfoChart;
var clusterOptions = {
chart: {
type: 'area',
renderTo: 'container',
events: {
load: function () {
S = this.series;
setInterval(function () {
var seconds = Math.round(new Date() / 1000);
seconds = seconds - 1397529601 + 1235;
console.log(seconds);
var shift = S[0].data.length > 10;
S[0].addPoint([seconds, {
y: 1,
yinfo: '192.168.119.10:cpuwarn'
}], true, shift);
S[1].addPoint([seconds, {
y: 1,
yinfo: '192.168.119.10:cpuwarn'
}], true, shift);
clusterInfoChart.redraw();
}, 3000);
}
}
},
title: {
text: 'clusterInfo'
},
xAxis: {
categories: [
'1205', '1210', '1215', '1220', '1225', '1230', '1235'],
tickmarkPlacement: 'on',
title: {
enabled: false
}
},
yAxis: {
title: {
text: 'Events'
},
labels: {
formatter: function () {
return this.value.y;
}
}
},
tooltip: {
formatter: function () {
return this.point.yinfo.replace(";", "<br>");
}
},
plotOptions: {
area: {
stacking: 'normal',
lineColor: '#666666',
lineWidth: 1,
marker: {
lineWidth: 1,
lineColor: '#666666'
}
}
},
series: [{
name: 'Alert',
data: [
{
y: 1,
yinfo: '192.168.119.10:cpuwarn'
}, {
y: 1,
yinfo: '192.168.119.10:cpuwarn'
}, {
y: 2,
yinfo: '192.168.119.10:cpuwarn;192.168.119.11:memwarn'
}, {
y: 1,
yinfo: '192.168.119.10:cpuwarn'
}, {
y: 2,
yinfo: '192.168.119.10:cpuwarn;192.168.119.11:memwarn'
}, {
y: 1,
yinfo: '192.168.119.10:cpuwarn'
}, {
y: 2,
yinfo: '192.168.119.10:cpuwarn;192.168.119.11:memwarn'
}
]
}, {
name: 'Warn',
data: [
{
y: 0,
yinfo: ''
}, {
y: 1,
yinfo: '192.168.119.10:cpuwarn'
}, {
y: 0,
yinfo: ''
}, {
y: 2,
yinfo: '192.168.119.10:cpuwarn;192.168.119.11:memwarn'
}, {
y: 1,
yinfo: '192.168.119.10:cpuwarn'
}, {
y: 0,
yinfo: ''
}, {
y: 1,
yinfo: '192.168.119.10:cpuwarn'
}
]
}]
};
Highcharts.setOptions({
global: {
useUTC: false
}
});
clusterInfoChart = new Highcharts.Chart(clusterOptions);
});
Just this format isn't proper:
[seconds, {
y: 1,
yinfo: '192.168.119.10:cpuwarn'
}]
Should be:
{
x: seconds,
y: 1,
yinfo: '192.168.119.10:cpuwarn'
}

Resources