Highcharts converting a column chart to a pie chart - highcharts

After reading many posts and tutorials concerning pie charts I am totally stuck. I have a column chart which work fine but I need to convert/change it to a pie chart.
The data for the chart comes from a data table via a query and is returns in Json format.
[{"name":"Month","data":["Jun"]},{"name":"percent","data":[55.68]},{"data":[20.45]},{"data":[7.95]},{"data":[15.91]}]
The big issue I am having is using the json result as I do when using a column chart.
My current column chart:
$(function () {
var categories=[];
var data4 =[];
var chart;
$(document).ready(function() {
$.getJSON("../charts/1-2-4-overall_month_chart.php?From=<?php echo $StartDate;?>&To=<?php echo $EndDate;?>", function(json) {
$.each(json,function(i,el) {
if (el.name=="Month")
categories = el.data;
else data4.push(el);
});
$('#container1').highcharts({
chart: {
renderTo: 'container',
type: 'column',
marginTop: 25,
marginRight: 25,
marginBottom: 25,
plotBackgroundColor: '#FCFFC5'
},
title: {
text: '',
},
subtitle: {
text: '',
x: -20
},
xAxis: {
categories: categories,
labels: {
enabled: true
}
},
yAxis: {
endOnTick: false,
max:101,
showFirstLabel: false,
lineColor:'#999',
lineWidth:1,
tickColor:'#666',
tickWidth:1,
tickLength:2,
tickInterval: 10,
gridLineColor:'#ddd',
title: {
text: 'Percentage %',
style: {
fontFamily: 'Tahoma',
color: '#000000',
fontWeight: 'bold',
fontSize: '10px'
}
},
plotLines: [{
color: '#808080'
}],
labels: {
align: 'left',
x: 0,
y: -2
}
},
legend: {
enabled: false,
itemStyle: {
font: '11px Trebuchet MS, Verdana, sans-serif',
color: '#000000'
},
itemHoverStyle: {
color: '#000000'
},
itemHiddenStyle: {
color: '#444'
}
},
colors: [
'#ff0000',
'#f49004',
'#3abf05',
'#8b8c8a',
],
plotOptions: {
column: {
colorByPoint: false
},
series: {
pointPadding: 3.25,
cursor: 'pointer',
pointWidth:30,
point: {
events: {
click: function() {
window.location.href = "1-4-detractors_chart_month.php";
}
}
},
legendIndex:0,
dataLabels: {
enabled: true,
//rotation: -90,
color: '#000000',
align: 'right',
cursor: 'pointer',
format: '{point.y:.2f}', // one decimal
y: -20, // 10 pixels down from the top
style: {
textShadow: false,
fontSize: '8px',
fontFamily: 'Verdana, sans-serif'
}
}
}
},
tooltip: {
enabled: false,
},
navigation: {
buttonOptions: {
verticalAlign: 'top',
y: -10
}
},
credits: {
enabled: false
},
series: data4,
lang: {
noData: "No data for your date<br /> selection"
},
noData: {
style: {
fontWeight: 'bold',
fontSize: '12px',
color: '#303030'
}
},
});
});
});
});

check Basic pie for more info. I have made some change in code specially in processing data for pie chart from ajax response. Check for the comments and I have also commented out code which are not required by pie chart
$(function() {
var categories = [];
var data4 = [];
var chart;
$(document).ready(function() {
/* $.getJSON("../charts/1-2-4-overall_month_chart.php?From=<?php echo $StartDate;?>&To=<?php echo $EndDate;?>", function(json) {
$.each(json,function(i,el) {
if (el.name=="Month")
categories = el.data;
else data4.push(el);
}); */
var data = [{
"name": "Month",
"data": ["Jun"]
}, {
"name": "percent",
"data": [55.68]
}, {
"data": [20.45]
}, {
"data": [7.95]
}, {
"data": [15.91]
}]
$.each(data, function(i, el) {
if (el.name == "Month")
categories = el.data;
//below is some change check https://www.highcharts.com/demo/pie-basic
else data4.push({
name: el.name,
y: el.data[0]
});
});
//console.log(JSON.stringify(data4))
$('#container').highcharts({
chart: {
renderTo: 'container',
type: 'pie', //change to pie
marginTop: 25,
marginRight: 25,
marginBottom: 25,
plotBackgroundColor: '#FCFFC5'
},
title: {
text: '',
},
subtitle: {
text: '',
x: -20
},
/* xAxis: {
categories: categories,
labels: {
enabled: true
}
},
yAxis: {
endOnTick: false,
max: 101,
showFirstLabel: false,
lineColor: '#999',
lineWidth: 1,
tickColor: '#666',
tickWidth: 1,
tickLength: 2,
tickInterval: 10,
gridLineColor: '#ddd',
title: {
text: 'Percentage %',
style: {
fontFamily: 'Tahoma',
color: '#000000',
fontWeight: 'bold',
fontSize: '10px'
}
},
plotLines: [{
color: '#808080'
}],
labels: {
align: 'left',
x: 0,
y: -2
}
},*/
legend: {
enabled: false,
itemStyle: {
font: '11px Trebuchet MS, Verdana, sans-serif',
color: '#000000'
},
itemHoverStyle: {
color: '#000000'
},
itemHiddenStyle: {
color: '#444'
}
},
colors: [
'#ff0000',
'#f49004',
'#3abf05',
'#8b8c8a',
],
plotOptions: {
/* column: {
colorByPoint: false
},*/
series: {
pointPadding: 3.25,
cursor: 'pointer',
pointWidth: 30,
point: {
events: {
click: function() {
window.location.href = "1-4-detractors_chart_month.php";
}
}
},
legendIndex: 0,
dataLabels: {
enabled: true,
//rotation: -90,
color: '#000000',
align: 'right',
cursor: 'pointer',
format: '{point.y:.2f}', // one decimal
y: -20, // 10 pixels down from the top
style: {
textShadow: false,
fontSize: '8px',
fontFamily: 'Verdana, sans-serif'
}
}
}
},
tooltip: {
enabled: false,
},
navigation: {
buttonOptions: {
verticalAlign: 'top',
y: -10
}
},
credits: {
enabled: false
},
series: [{
data: data4
}],
lang: {
noData: "No data for your date<br /> selection"
},
noData: {
style: {
fontWeight: 'bold',
fontSize: '12px',
color: '#303030'
}
},
});
});
//});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://code.highcharts.com/highcharts.js"></script>
<script src="https://code.highcharts.com/modules/exporting.js"></script>
<div id="container" style="min-width: 310px; height: 400px; max-width: 600px; margin: 0 auto"></div>

Related

HighCharts chart reloads on initial load

I have a bunch of HighCharts running data from Google Sheets, and some of them firstly render the plot area then keep reloading the data on the chart, and I can't figure out why. Is this just a HighCharts thing, or something I can fix?
This is what's happening https://youtu.be/ddM-WxCAczM
This is the Google Sheet I'm loading into HighCharts cloud https://docs.google.com/spreadsheets/d/e/2PACX-1vSQEXUaZFqT3Oatl3AK8S-bqq6vNs5vDjoG2puaFvQ7LsSGB5dIaBk0Kp2aHWE2lbFEms9gZ6r36TTQ/pubhtml
Here's the custom code I'm applying in HighCharts cloud to render the chart how I need it:
Highcharts.merge(true, options, {
chart: {
height: 445,
marginTop: 70,
spacingBottom:-100,
style: {
fontFamily: '"Trebuchet MS","Trebuchet","Helvetica","Lucida Sans Unicode","Lucida Sans",Tahoma,sans-serif',
},
events: {
load: function () {
this.update({
exporting: {
filename: this.options.title.text,
}
});
}
},
plotBorderColorLeft: '#ccc',
plotBorderWidth: 0,
backgroundColor: {
stops: [
[1, 'rgb(255, 255, 255)'],
]
}
},
plotOptions: {
column: {
pointPlacement: 'between'
},
series: {
marker: {
enabled: false,
},
cursor: 'arrow'
}
},
yAxis: {
plotLines: [{
color: '#010101',
width: 2,
value: 0,
zIndex: 5
}],
lineWidth: 1.5,
gridLineWidth: 0,
lineColor: '#010101',
tickWidth: 1.5,
tickLength: 4,
tickColor: '#010101',
title: {
align: 'high',
offset: -10,
text: '(%)',
rotation: 0,
y: -12,
style: {
fontSize: '14px'
},
},
labels: {
enabled: true,
style: {
fontSize: '13px'
}
},
startOnTick: true,
endOnTick: true,
tickInterval: 1,
tickPosition: 'inside',
tickmarkPlacement: 'on',
},
xAxis: {
title: {
text: 'Date',
style: {
display: 'none'
}
},
offset:-127,
useHTML: true,
labels: {
enabled: true,
rotation: -90,
x: 14,
style: {
fontSize: '16px'
},
y:160
},
lineWidth:2,
lineColor: '#010101',
tickWidth:2,
tickPosition: 'inside',
tickLength:4,
tickColor: '#010101',
tickmarkPlacement: 'on',
startOnTick: false,
endOnTick: false,
min:.0,
max:40.4
},
credits: {
enabled:false
},
legend: {
symbolRadius: 0,
floating:true,
itemStyle: {
font: '14px Trebuchet MS, Trebuchet, "Helvetica", Verdana, sans-serif',
color: '#010101'
},
itemMarginTop: 5,
floating: true,
layout: 'vertical',
align: 'left',
verticalAlign: 'top',
enabled: true,
x: 50,
y: 15
},
subtitle: {
style: {
display: 'none'
},
y: 0
},
title: {
style: {
display: 'none'
},
y: 0
},
tooltip: {
valueSuffix: '%'
},
exporting: {
buttons: {
contextButton: {
enabled: true,
y:-10,
x:10,
text: 'Download',
menuItems: [
"printChart",
"separator",
"downloadPNG",
"downloadJPEG",
"downloadPDF",
"downloadSVG",
"separator",
"downloadCSV",
"downloadXLS",
{
textKey: 'viewData',
text: 'Toggle data table',
onclick: function() {
if (this.dataTableDiv && this.dataTableDiv.style.display !== 'none') {
this.dataTableDiv.style.display = 'none';
} else {
this.viewData();
this.dataTableDiv.style.display = '';
}
}
}
]
}
}
}
});

Highcharts series (column) names of x axis

I have a script that returns a chart (Highcharts) and it works fine apart from not displaying the names of the columns on the x axis. Can anyone see where I have gone wrong.
My Json:
[{"data":[30.95]},{"data":[2.38]},{"data":[66.67]}]
My script:
$(function () {
var colors = ['#FF0000','#FF9900','#009900'];
colorIterator = 0;
var chart;
$(document).ready(function() {
$.getJSON("../charts/1-2-4-reports_chart.php?TAG=<?php echo $_POST['SectionVar'];?>&From=<?php echo $StartDate;?>&To=<?php echo $EndDate;?>", function(json) {
chart = new Highcharts.Chart({
chart: {
renderTo: 'container1',
type: 'column',
height: 200,
marginRight: 25,
marginBottom: 25,
plotBackgroundColor: '#FCFFC5',
style: {
fontFamily: 'serif',
fontSize: '8px',
}
},
title: {
text: 'Net Promoter Score: <?php echo $_POST['SectionVar'];?>',
x: -20,
style: {
fontFamily: 'Tahoma',
color: '#000000',
fontWeight: 'normal',
fontSize: '11px'
} //center
},
subtitle: {
text: '',
},
xAxis: {
categories: ['Detractors', 'Passives', 'Promoters'],
title: {
text: ''
}
},
yAxis: {
//reversedStacks: false,
endOnTick: false,
max:101,
showFirstLabel: false,
lineColor:'#999',
lineWidth:1,
tickColor:'#666',
tickWidth:1,
tickLength:2,
tickInterval: 10,
gridLineColor:'#ddd',
title: {
text: '',
style: {
fontFamily: 'Tahoma',
color: '#000000',
fontWeight: 'bold',
fontSize: '8px'
}
},
plotLines: [{
color: '#808080'
}]
},
credits: {
enabled: false
},
tooltip: {
formatter: function() {
return '<b>Guest responses: '+ this.y +'<br/>'+ this.series.name +'</b><br/>Month:'+
this.x;
}
},
navigation: {
buttonOptions: {
verticalAlign: 'top',
y: -10,
x: -20
}
},
legend: {
enabled: false,
layout: 'vertical',
align: 'right',
verticalAlign: 'top',
x: -10,
y: 100,
borderWidth: 1
},
colors: [
'#FF0000',
'#FF9900',
'#009900',
],
plotOptions: {
column: {
colorByPoint: false
},
series: {
type: 'column',
cursor: 'pointer',
pointWidth: 30,
point: {
events: {
//click: function() {
//location.href = "feedback-items_detractors_iframe.php?FromDate1=<?php echo $StartDate;?>&ToDate1=<?php echo $EndDate;?> target='iframe2'";
//}
}
},
legendIndex:0,
dataLabels: {
enabled: true,
color: '#000000',
align: 'center',
cursor: 'pointer',
//borderRadius: 5,
//backgroundColor: 'rgba(252, 255, 255, 255)',
//borderWidth: 1,
//borderColor: '#AAA',
y: -6,
format: '{y:.2f} %', // one decimal
y: -20, // 10 pixels down from the top
this.series.name
style: {
textShadow: false,
fontSize: '8px',
fontFamily: 'Verdana, sans-serif'
}
}
}
},
exporting: {
chartOptions: { // specific options for the exported image
plotOptions: {
series: {
dataLabels: {
enabled: true
}
}
}
},
fallbackToExportServer: false
},
series: json,
});
});
});
});
Many thanks in advance for your time.
You made some syntax errors in your code, fixed version below:
$(function() {
var colors = ['#FF0000', '#FF9900', '#009900'];
var colorIterator = 0;
var chart;
$(document).ready(function() {
const json = [{"data":[30.95]},{"data":[2.38]},{"data":[66.67]}]
setTimeout(function() {
chart = Highcharts.chart('container', {
chart: {
renderTo: 'container1',
type: 'column',
height: 200,
marginRight: 25,
marginBottom: 25,
plotBackgroundColor: '#FCFFC5',
style: {
fontFamily: 'serif',
fontSize: '8px',
}
},
title: {
text: '',
x: -20,
style: {
fontFamily: 'Tahoma',
color: '#000000',
fontWeight: 'normal',
fontSize: '11px'
} //center
},
subtitle: {
text: '',
},
xAxis: {
categories: ['Detractors', 'Passives', 'Promoters'],
title: {
text: ''
}
},
yAxis: {
//reversedStacks: false,
endOnTick: false,
max: 101,
showFirstLabel: false,
lineColor: '#999',
lineWidth: 1,
tickColor: '#666',
tickWidth: 1,
tickLength: 2,
tickInterval: 10,
gridLineColor: '#ddd',
title: {
text: '',
style: {
fontFamily: 'Tahoma',
color: '#000000',
fontWeight: 'bold',
fontSize: '8px'
}
},
plotLines: [{
color: '#808080'
}]
},
credits: {
enabled: false
},
tooltip: {
formatter: function() {
return '<b>Guest responses: ' + this.y + '<br/>' + this.series.name + '</b><br/>Month:' +
this.x;
}
},
navigation: {
buttonOptions: {
verticalAlign: 'top',
y: -10,
x: -20
}
},
legend: {
enabled: false,
layout: 'vertical',
align: 'right',
verticalAlign: 'top',
x: -10,
y: 100,
borderWidth: 1
},
colors: [
'#FF0000',
'#FF9900',
'#009900',
],
plotOptions: {
column: {
colorByPoint: false
}
},
series: {
type: 'column',
cursor: 'pointer',
pointWidth: 30,
point: {
events: {
}
},
legendIndex: 0,
dataLabels: {
enabled: true,
color: '#000000',
align: 'center',
cursor: 'pointer',
y: -6,
format: '{y:.2f} %', // one decimal
y: -20, // 10 pixels down from the top
style: {
textShadow: false,
fontSize: '8px',
fontFamily: 'Verdana, sans-serif'
}
}
},
exporting: {
chartOptions: { // specific options for the exported image
plotOptions: {
series: {
dataLabels: {
enabled: true
}
}
}
},
fallbackToExportServer: false
},
series: json,
});
});
});
});
https://jsfiddle.net/0kjojak9/

Highcharts not display chart

I am having an issue displaying my chart. I am creating a script that displays three charts with a print button to print all the chart to one PDF.
The JSON call is returning:
[{"name":"Month"},{"name":"percent","data":[9.52]}]
I am not getting any errors in the browser console, can any one see where I am going wrong.
$(function () { //1
var chart1, chart2, chart3;
var categories=[];
//var chart;
var data2 =[];
$(document).ready(function() { //2
$.getJSON("../charts/1-2-4-detractors_month_chart.php?From=<?php echo $_GET['From'];?>&To=<?php echo $_GET['To'];?>", function(json) { //3
$.each(json,function(i,el) { //4
if (el.name=="Month")
categories = el.data;
else data2.push(el);
});
chart1 = new Highcharts.Chart({
chart: {
renderTo: 'container1',
type: 'column',
marginTop: 25,
marginRight: 25,
marginBottom: 25,
plotBackgroundColor: '#FCFFC5',
style: {
fontFamily: 'serif',
fontSize: '8px',
}
},
title: {
text: '',
},
subtitle: {
text: '',
},
xAxis: {
categories: categories,
labels: {
enabled: false
}
},
yAxis: {
endOnTick: false,
max:101,
showFirstLabel: false,
lineColor:'#999',
lineWidth:1,
tickColor:'#666',
tickWidth:1,
tickLength:2,
tickInterval: 10,
gridLineColor:'#ddd',
title: {
text: '',
style: {
fontFamily: 'Tahoma',
color: '#000000',
fontWeight: 'bold',
fontSize: '8px'
}
},
plotLines: [{
color: '#808080'
}]
},
legend: {
enabled: false,
},
colors: ['#FF0000','#FF2F2F'],
plotOptions: {
column: {
colorByPoint: true
},
series: {
cursor: 'pointer',
pointWidth: 20,
point: {
events: {
//click: function() {
//location.href = "feedback-items_detractors_iframe.php?FromDate1=<?php echo $StartDate;?>&ToDate1=<?php echo $EndDate;?> target='iframe2'";
//}
}
},
legendIndex:0,
dataLabels: {
enabled: true,
color: '#000000',
align: 'center',
cursor: 'pointer',
borderRadius: 5,
backgroundColor: 'rgba(252, 255, 255, 255)',
borderWidth: 1,
borderColor: '#AAA',
y: -6,
format: '{y:.2f} %', // one decimal
y: -20, // 10 pixels down from the top
style: {
textShadow: false,
fontSize: '8px',
fontFamily: 'Verdana, sans-serif'
}
}
}
},
tooltip: {
style: {
fontSize: '7pt',
fontFamily: 'Verdana, sans-serif'
},
valueDecimals: 1,
formatter: function() {
return '<b>Guest responses:<br/> '+ this.y +'%</b>';
}
},
navigation: {
buttonOptions: {
verticalAlign: 'top',
y: -10,
x: -20
}
},
credits: {
enabled: false
},
series: data2,
lang: {
noData: "No data"
},
noData: {
style: {
fontWeight: 'normal',
fontSize: '12px',
color: '#303030'
}
},
});
});
});
//});
//--------------------------------------------------------------------
$("#print").click(function () {
printCharts([chart1, chart2, chart3]);
});
//--------------------------------------------------------------------
function printCharts(charts) {
var origDisplay = [],
origParent = [],
body = document.body,
childNodes = body.childNodes;
// hide all body content
Highcharts.each(childNodes, function (node, i) {
if (node.nodeType === 1) {
origDisplay[i] = node.style.display;
node.style.display = "none";
}
});
// put the charts back in
$.each(charts, function (i, chart) {
origParent[i] = chart.container.parentNode;
body.appendChild(chart.container);
});
// print
window.print();
// allow the browser to prepare before reverting
setTimeout(function () {
// put the chart back in
$.each(charts, function (i, chart) {
origParent[i].appendChild(chart.container);
});
// restore all body content
Highcharts.each(childNodes, function (node, i) {
if (node.nodeType === 1) {
node.style.display = origDisplay[i];
}
});
}, 500);
}
});

How do get highcharts combo column scatter to work?

Trying to create a combo chart of with 3 column series and 1 scatter series; column should be 100% and scatter overlaid on it. When I use plotOptions: {column: {stacking: "percent"}, the columns are maximized in the plot area but scatter series goes to bottom of chart; when replace with plotOptions: {column: {stacking: "normal"}, it displays well but columns are not maximizing the plot area. Ideas?
Highcharts.chart('container', {
chart: {
ignoreHiddenSeries: false,
backgroundColor: "#FFFFFF",
width: 509,
height: 400,
borderColor: "#FFFFFF",
borderWidth: 1,
plotShadow: false
},
title: {
text: "Your organization in comparison",
style: {color: "#333333", fontFamily: "Arial", fontSize: 16, fontWeight: "bold"}
},
legend: {
enabled: true,
verticalAlign: "bottom",
align: "center",
symbolRadius: 0,
style: {color: "#333333", fontFamily: "Arial", fontSize: 13}
},
plotOptions: {
column: {stacking: "percent"},
// column: {stacking: "normal"},
series: {animation: true}},
tooltip: {enabled: false},
yAxis: {title: {text: null}, labels: {enabled: false}, gridLineWidth: 0, reversedStacks: false},
xAxis: {
title: {text: null},
categories: ['Experience', 'Security', 'Management'],
labels: {enabled: true, style: {color: "#333333", fontFamily: "Arial", fontSize: 13}},
gridLineWidth: 0,
reversedStacks: false
},
series: [{
type: "column",
name: "Low",
invertIfNegative: false,
color: "#002E73",
showInLegend: true,
data: [{y: 0.42}, {y: 0.42}, {y: 0.48}],
dataLabels: {
enabled: false,
verticalAlign: "top",
style: {color: "#FFFFFF", fontFamily: "Arial", fontSize: 13, textOutline: ""}
}
}, {
type: "column",
name: "Medium",
invertIfNegative: false,
color: "#297EFF",
showInLegend: true,
data: [{y: 0.37}, {y: 0.47}, {y: 0.36}],
dataLabels: {enabled: false}
}, {
type: "column",
name: "High",
invertIfNegative: false,
color: "#B8D4FF",
showInLegend: true,
data: [{y: 0.21}, {y: 0.11}, {y: 0.16}],
dataLabels: {enabled: false}
}, {
type: "scatter",
name: "Your organization today",
invertIfNegative: false,
color: "#FFC000",
lineWidth: 0,
marker: {enabled: true, radius: 14},
states: {hover: {lineWidthPlus: 0}},
showInLegend: true,
data: [{y: 0.21}, {y: 0.21}, {y: 0.24}],
dataLabels: {enabled: false}
}],
credits: {enabled: false}
})
<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>
<div id="container" style="width: 600px; height: 300px; margin: 0 auto"></div>
Your should use Multiple axes to make combinations chart.
Refer document about YAxis here: http://api.highcharts.com/highcharts/yAxis
I've fixed your code as bellow. Please try!
Highcharts.chart('container', {
chart: {
ignoreHiddenSeries: false,
backgroundColor: "#FFFFFF",
width: 509,
height: 400,
borderColor: "#FFFFFF",
borderWidth: 1,
plotShadow: false
},
title: {
text: "Your organization in comparison",
style: {
color: "#333333",
fontFamily: "Arial",
fontSize: 16,
fontWeight: "bold"
}
},
legend: {
enabled: true,
verticalAlign: "bottom",
align: "center",
symbolRadius: 0,
style: {
color: "#333333",
fontFamily: "Arial",
fontSize: 13
}
},
plotOptions: {
column: {
stacking: "percent"
},
// column: {stacking: "normal"},
series: {
animation: true
}
},
tooltip: {
enabled: false
},
// Create Multiple axes
yAxis: [{
title: {
text: null
},
labels: {
enabled: false
},
gridLineWidth: 0,
reversedStacks: false
}, {
title: {
text: null
},
labels: {
enabled: false
},
gridLineWidth: 0,
reversedStacks: false
}],
xAxis: {
title: {
text: null
},
categories: ['Experience', 'Security', 'Management'],
labels: {
enabled: true,
style: {
color: "#333333",
fontFamily: "Arial",
fontSize: 13
}
},
gridLineWidth: 0,
reversedStacks: false
},
series: [{
type: "column",
name: "Low",
invertIfNegative: false,
color: "#002E73",
showInLegend: true,
data: [{
y: 0.42
}, {
y: 0.42
}, {
y: 0.48
}],
dataLabels: {
enabled: false,
verticalAlign: "top",
style: {
color: "#FFFFFF",
fontFamily: "Arial",
fontSize: 13,
textOutline: ""
}
}
}, {
type: "column",
name: "Medium",
invertIfNegative: false,
color: "#297EFF",
showInLegend: true,
data: [{
y: 0.37
}, {
y: 0.47
}, {
y: 0.36
}],
dataLabels: {
enabled: false
}
}, {
type: "column",
name: "High",
invertIfNegative: false,
color: "#B8D4FF",
showInLegend: true,
data: [{
y: 0.21
}, {
y: 0.11
}, {
y: 0.16
}],
dataLabels: {
enabled: false
}
}, {
yAxis: 1, // Define axis will be use here
type: "scatter",
name: "Your organization today",
invertIfNegative: false,
color: "#FFC000",
lineWidth: 0,
marker: {
enabled: true,
radius: 14
},
states: {
hover: {
lineWidthPlus: 0
}
},
showInLegend: true,
data: [{
y: 0.21
}, {
y: 0.21
}, {
y: 0.24
}],
dataLabels: {
enabled: false
}
}],
credits: {
enabled: false
}
})
<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>
<div id="container" style="width: 600px; height: 300px; margin: 0 auto"></div>

HighCharts not displaying chart

I have produce many scripts in the past that use the HighCharts functions but for some reason with the current script I am working on I have lost the plot.
I have a script that runs a MySQL query and produces the following result:
get_data.php
[{"name":"Room","data":[1267,1268,2371,1254,2374,1364,1378,1385,2372,2242,256,2237,2254,2261,2260,2273,2271,2268,2253,2379,2378,2377,2376,2233,2234,2243,2380,2383,2107,2108,2240,2246,2359,2381,2384,2361,2373,2395,1369,2398,2393,2391,2390,2387,2363,2109,2238,2239,2247,2248,2249,2251,2265,2266,2133,2117,2119,2118,2120,2106,2103,2101,2263,2389,2375,2369,2235,2258,1253,1266,1238,2264,2110,2114,2115,2394,2399]}]
I then have a script that calls Script1 and should display a chart.
Chart script:
$(function () {
var categories=[];
var data2 =[];
var chart;
$(document).ready(function() {
$.getJSON("get_data.php", function(json) {
$.each(json,function(i,el) {
if (el.name=="Room")
categories = el.data;
else data2.push(el);
});
$('#container1').highcharts({
chart: {
renderTo: 'container',
type: 'column',
marginTop: 80,
marginRight: 30,
marginBottom: 100, events :{
load: function(){
this.series[1].hide();
}
}
},
title: {
text: '',
x: -20, //center
style: {
fontFamily: 'Tahoma',
color: '#000000',
fontWeight: 'bold',
fontSize: '11px'
}
},
subtitle: {
text: '',
x: -20
},
xAxis: {
categories: categories,
labels: {
style: {
color: '#F00',
font: '9px Tahoma, Verdana, sans-serif'
}
}
},
yAxis: {
max:100,
showFirstLabel: false,
lineColor:'#999',
lineWidth:1,
tickColor:'#666',
tickWidth:1,
tickLength:2,
tickInterval: 10,
gridLineColor:'#ddd',
title: {
text: 'Percentage',
style: {
fontFamily: 'Tahoma',
color: '#000000',
fontWeight: 'bold',
fontSize: '9px'
}
},
stackLabels: {
enabled: true,
y: 10,
formatter: function() {
//console.log((this.axis.series[1].yData[this.x] ));
return (this.axis.series[1].yData[this.x] ) ;
},
style: {
color: '#000000',
font: '11px Tahoma, Verdana, sans-serif'
}
}
},
plotOptions: {
series: {
pointWidth: 15,
stacking: 'normal',
dataLabels: {
enabled: true,
rotation: -90,
color: '#000000',
align: 'center',
format: '{point.y:.1f}', // one decimal
y: 10, // 10 pixels down from the top
style: {
fontSize: '9px',
textShadow: false,
fontFamily: 'Verdana, sans-serif'
}
}
}
},
tooltip: {
formatter: function() {
return '<b>'+ this.series.name +'</b><br/>'+
this.x +': '+ this.y;
}
},
credits: {
enabled: false
},
legend: {
enabled: false
},
series: data2
});
});
});
});

Resources