Highcharts y-axis unable to start from the given value - highcharts

I am using high charts to generate graphs. As per my requirement I want to generate the graph with dynamic minimum and maximum values. Even though I assigned minimum and maximum value, my graph is starting from less than my minimum value. I want my graph to be start with the user defined minimum value such that no white space should be there between axis and graph
Following is the fiddle
http://jsfiddle.net/0e4rqb88/
$(document).ready(function() {
var data1 = [{
"maximumLean": 4.6,
"usl": 5.5,
"framesFlag": 0,
"emptyConesFlag": 0,
"ninetyFivePFlag": 0,
"sigma3": 4.8,
"sigma4": 4.4,
"sigma1": 4.6,
"arrow": 0,
"inSpec": 100.0,
"sigma2": 4.7,
"recentLean2": 4.600084552015582,
"recentLean1": 4.368252611538148,
"recentLean4": 4.369438416014055,
"recentLean3": 4.495304457897132,
"check2Sigma": 1,
"ninetyFivePValue": 0.1,
"meanFlag": 0,
"sigma6": 4.2,
"sigma5": 4.3,
"conesFlag": 0,
"targetSpec": 4.5,
"check3Sigma": 1,
"cpm": 1.1,
"emptyCone": 8.9,
"ninetyPFlag": 0,
"lsl": 3.5,
"sampleSize": 30,
"minimumLean": 4.4,
"check1Sigma": -1,
"ninetyPValue": 0.1,
"sd": 0.1,
"fpm": 1.0,
"fc": 123,
"lean": 4.4,
"median": 4.4,
"medianFlag": 0,
"inspecFlag": 0,
"cl": 4.5,
"sdFlag": 0,
"cc": 135
}, {
"lean": 4.5
}, {
"lean": 4.6
}, {
"lean": 4.4
}, {
"start": "08-12-2014 12:00:00",
"end": "08-12-2014 14:00:00"
}]
$('#data').val(JSON.stringify(data1[0]));
var x = 1;
var inSpec = 0;
var avgLean = 0;
var mean = 0;
var median = 0;
var sd = 0;
var maximum = 0;
var minimum = 0;
var sigma1 = 0;
var sigma2 = 0;
var sigma3 = 0;
var sigma4 = 0;
var sigma5 = 0;
var sigma6 = 0;
var avgLeanPercent = 0;
var sampleSize = 0;
//
var meandataofHighChart = 0;
var sigdata = [];
var dataofHighChart = [];
var maxChartVal = 0;
var minChartVal = 0;
for (var event in data1) {
var dataCopy = data1[event];
if (x == 1) {
mean = dataCopy.cl;
sd = dataCopy.sd;
median = dataCopy.median;
maximum = dataCopy.maximumLean;
minimum = dataCopy.minimumLean;
sigma1 = dataCopy.sigma1;
sigma2 = dataCopy.sigma2;
sigma3 = dataCopy.sigma3;
sigma4 = dataCopy.sigma4;
sigma5 = dataCopy.sigma5;
sigma6 = dataCopy.sigma6;
emptyCone = dataCopy.emptyCone;
sampleSize = dataCopy.sampleSize != undefined ? dataCopy.sampleSize : 20;
//alert(" Cone "+conesPerMinute.toFixed(1)+" Frame "+dataCopy.fpm);
sigdata.push(sigma6);
sigdata.push(sigma5);
sigdata.push(sigma4);
sigdata.push(mean);
sigdata.push(sigma1);
sigdata.push(sigma2);
sigdata.push(sigma3);
//dataofHighChart.push(lean);
}
dataofHighChart.push(dataCopy.lean);
meandataofHighChart = (mean);
x++;
}
maxChartVal = maximum > sigma3 ? maximum : sigma3;
minChartVal = minimum < sigma6 ? minimum : sigma6;
console.info("sigdata " + sigdata);
console.info("maximum " + maximum);
console.info("sigma3 " + sigma3);
console.info("minimum " + minimum);
console.info("sigma6 " + sigma6);
console.info("maxChartVal " + maxChartVal);
console.info("minChartVal " + minChartVal);
minChartVal = minChartVal > 0 ? (minChartVal) - 0.1000000000000005 : 0;
maxChartVal = maxChartVal > 0 ? (maxChartVal) + 0.1000000000000005 : 0;
console.info("maxChartVal " + maxChartVal);
console.info("minChartVal " + minChartVal);
var highchart = new Highcharts.Chart({
chart: {
marginRight: 80,
zoomType: "x",
renderTo: 'chart_div', // like ,
height: 350
},
title: {
text: 'X-Bar Chart',
style: {
"font-weight": "bold",
"font-size": "16px;"
}
},
xAxis: {
floor: 1,
allowDecimals: false,
title: {
text: "Sample Number (N = " + sampleSize + ")",
style: {
"font-weight": "bold",
"font-size": "14px;"
}
}
},
tooltip: {
formatter: function() {
return 'Sample Number : ' + this.point.x + '<br/> % Lean : ' + this.point.y + ' %';
}
},
yAxis: [{
lineWidth: 1,
max: maxChartVal,
min: minChartVal,
floor: minChartVal,
title: {
text: '% Lean',
style: {
"font-weight": "bold",
"font-size": "14px;"
}
},
plotLines: [{
value: meandataofHighChart,
color: '#000000',
width: 2,
zIndex: 4
}],
minorGridLineWidth: 0,
gridLineWidth: 0,
alternateGridColor: null,
plotBands: [{
from: minChartVal,
to: sigdata[1],
color: '#FF7F7F'
}, {
from: sigdata[1],
to: sigdata[2],
color: '#FFFF7F'
}, {
from: sigdata[2],
to: sigdata[3],
color: '#7FBF7F'
}, {
from: sigdata[3],
to: sigdata[4],
color: '#7FBF7F'
}, {
from: sigdata[4],
to: sigdata[5],
color: '#FFFF7F'
}, {
from: sigdata[5],
to: maxChartVal,
color: '#FF7F7F'
}]
}],
series: [{
name: '% Lean',
data: dataofHighChart,
color: '#00407F'
}]
});
});

By default, the startOnTick option and endOnTick option is true for the yAxis. If you set those to false, highcharts will respect your min/max options.
Here's updated fiddle.
yAxis: [{
...
max:maxChartVal,
min:minChartVal,
startOnTick: false,
endOnTick: false,
...

Related

How to make the regression line through the origin in highcharts

I am trying to make the regression to start from the origin , x=y=0. Is this possible to do. some say it is not good to do so but for some purposes I need to make the line through the origin. I am using highcharts.
How about adding a point to the regression series with x = y = 0 and setting the marker to disabled in order to hide it?
let discipline = [
{
name: "Football",
data: "football"
}
];
Highcharts.getJSON(
"https://raw.githubusercontent.com/mekhatria/demo_highcharts/master/olympic2012.json?callback=?",
function (data) {
function regression(arrWeight, arrHeight) {
let r, sy, sx, b, a, meanX, meanY;
r = jStat.corrcoeff(arrHeight, arrWeight);
sy = jStat.stdev(arrWeight);
sx = jStat.stdev(arrHeight);
meanY = jStat(arrWeight).mean();
meanX = jStat(arrHeight).mean();
b = r * (sy / sx);
a = meanY - meanX * b;
//Set up a line
let y1, y2, x1, x2;
x1 = jStat.min(arrHeight);
x2 = jStat.max(arrHeight);
y1 = a + b * x1;
y2 = a + b * x2;
return {
line: [
//Add x = 0, y = 0 to your regression logic?
{x: 0, y: 0, marker: {enabled: false}},
{x: x1, y: y1, marker: {enabled: true}},
{x: x2, y: y2, marker: {enabled: true}},
],
r
};
}
const getData = (continentName) => {
let temp = [],
tempWeight = [],
tempHeight = [];
data.forEach((elm) => {
if (
elm.continent == continentName &&
elm.weight > 0 &&
elm.height > 0
) {
temp.push([elm.height, elm.weight]);
tempWeight.push(elm.weight);
tempHeight.push(elm.height);
}
});
let { line, r } = regression(tempWeight, tempHeight);
return [temp, line, r];
};
const getDataSport = (sportName) => {
let temp = [],
tempWeight = [],
tempHeight = [];
data.forEach((elm) => {
if (elm.sport == sportName && elm.weight > 0 && elm.height > 0) {
temp.push([elm.height, elm.weight]);
tempWeight.push(elm.weight);
tempHeight.push(elm.height);
}
});
let { line, r } = regression(tempWeight, tempHeight);
return [temp, line, r];
};
let series = [],
visible = false,
index = 0,
activate = ["Football"];
discipline.forEach((e) => {
if (activate.indexOf(e.name) > -1) {
visible = true;
} else {
visible = false;
}
let [scatterData, line, r] = getDataSport(e.data);
series.push(
{
type: "scatter",
visible: visible,
name: e.name,
data: scatterData
},
{
name: e.name,
visible: visible,
r: r,
data: line
}
);
});
Highcharts.chart("container", {
chart: {
type: "line",
zoomType: "y",
},
title: {
text: "2012 Olympic football athletes' weight and height relationship"
},
xAxis: {
title: {
text: "Height"
},
labels: {
format: "{value} m"
},
},
yAxis: {
title: {
text: "Weight"
},
labels: {
format: "{value} kg"
}
},
legend: {
enabled: true
},
plotOptions: {
scatter: {
marker: {
radius: 2.5,
symbol: "circle",
states: {
hover: {
enabled: true,
lineColor: "rgb(100,100,100)"
}
}
},
states: {
hover: {
marker: {
enabled: false
}
}
}
},
line: {
lineWidth: 2.5
}
},
tooltip: {
formatter: function () {
if (this.series.data.length > 2) {
return (
this.series.name +
"<br/>Height: " +
this.x +
" m<br/>Weight: " +
this.y +
" kg"
);
} else {
return (
this.series.name +
"<br/>r: " +
this.series.userOptions.r.toFixed(2)
);
}
}
},
series: series
});
}
);
<script src="https://code.highcharts.com/highcharts.js"></script>
<script src="https://code.highcharts.com/modules/data.js"></script>
<script src="https://code.highcharts.com/highcharts-more.js"></script>
<script src="https://code.highcharts.com/modules/export-data.js"></script>
<script src="https://code.highcharts.com/modules/accessibility.js"></script>
<script src="https://cdn.jsdelivr.net/npm/jstat#latest/dist/jstat.min.js"></script>
<script src="https://code.highcharts.com/modules/exporting.js"></script>
<div id="container"></div>

Highcharts gantt chart : Task progress indicator need to show a single task for various status like completed,inprogress etc with different colors

Refer the image
var markers = JSON.parse('<%=ConvertDataTabletoString("GetTaskWorkPercentage","2",null,1,10) %>');
var Arrayset = [];
var starts1 = [];
var ends1 = [];
var val1 = [];
var val2 = [];
if (markers != null) {
if (markers.length > 0) {
var prj = document.getElementById("param1").value;
for (var i = 0; i < markers.length; i++) {
var syearval = parseInt(markers[i].ActualStart.substr(0, 4));
var smonthval = parseInt(markers[i].ActualStart.substr(5, 2)) - 1;
var sdateval = parseInt(markers[i].ActualStart.substr(8, 2));
var eyearval = parseInt(markers[i].ActualEnd.substr(0, 4));
var emonthval = parseInt(markers[i].ActualEnd.substr(5, 2)) - 1;
var edateval = parseInt(markers[i].ActualEnd.substr(8, 2));
val1 = [Date.UTC(syearval, smonthval, sdateval)];
val2 = [Date.UTC(eyearval, emonthval, edateval)];
starts1.push(val1[0]);
ends1.push(val2[0]);
Arrayset.push({
name: markers[i].Task,
completed: markers[i].Percentages,
start: starts1[i],
end: ends1[i]
});
}
MainLoadChart(Arrayset);
}
}
function MainLoadChart(array) {
var dta = array;
Highcharts.ganttChart('container8', {
title: {
text: 'Task Progress Indicator Status'
},
tooltip: {
formatter()
{
//let output = `<span style="font-size: 10px">${this.point.series.name}</span><br>
let output = ` <span style="font-size: 20px;color:green">${prj}</span><br>
<span><b>${this.key}(Overall Subtask Percentage):${this.point.completed}% </b></span><br>
<span>Start: ${Highcharts.dateFormat('%A, %e. %b, %Y', this.x)}</span><br>
<span>End: ${Highcharts.dateFormat('%A, %e. %b, %Y', this.x2)}</span>`
return output
}
},
series: [{
data: dta,
dataLabels: {
formatter() {
//return this.point.completed;
let output1 = ` <span style="font-size: 10px">${this.point.completed}%</span>`
return output1
}
}]
});
}
Currently I´m showing the output of overall subtask. I need to show in a single task progress (overall) for various status like completed, inprogress, hold, returned with different (multiple) colors and style. So that values should not overlap or hide like datalabel values.
You should be able to achieve it by using yAxis.categories and assigning data to this one category.
Demo: https://jsfiddle.net/BlackLabel/19L48qy5/
...
yAxis: {
categories: ['Prototyping'],
},
series: [{
name: 'Project 1',
data: [{
name: 'test1',
start: Date.UTC(2014, 10, 18),
end: Date.UTC(2014, 10, 25),
y: 0
}, {
color: 'red',
name: 'test2',
start: Date.UTC(2014, 10, 18),
end: Date.UTC(2014, 10, 22),
y: 0
}, {
color: 'green',
name: 'test3',
start: Date.UTC(2014, 10, 18),
end: Date.UTC(2014, 10, 20),
y: 0
}]
}]
...
API: https://api.highcharts.com/gantt/yAxis.categories

why x-axis showing alternate months rather every month?

Following is my highcharts config, can you help me to why my alternate months are coming, and if i want to show every month, how do i do it ? Also, to change width of the bar if showing every month.
Highcharts.chart("energy_chart", {
chart: {
type: "column",
spacingBottom: 15,
spacingTop: 10,
spacingLeft: 10,
spacingRight: 10,
backgroundColor: "#f2f2f2",
events: {
load: function() {
var fin = new Date();
var finDate = fin.getDate();
var finMonth = fin.getMonth();
var finYear = fin.getFullYear();
var ini = new Date();
ini.setFullYear(ini.getFullYear() - 1);
var iniDate = ini.getDate();
var iniMonth = ini.getMonth();
var iniYear = ini.getFullYear();
if (this.yAxis[0].dataMax == 0) {
this.yAxis[0].setExtremes(null, 1);
}
//this.yAxis.set
console.log(new Date(Date.UTC(iniYear, iniMonth, iniDate)))
console.log(new Date(Date.UTC(finYear, finMonth, finDate)))
this.xAxis[0].setExtremes(
Date.UTC(iniYear, iniMonth, iniDate),
Date.UTC(finYear, finMonth, finDate)
);
},
drilldown: function(e) {
console.log('drilldown')
var charts_this = this;
var inidrillDate = new Date(e.point.x);
setTimeout(function() {
inidrillDate.setDate(0);
inidrillDate.setMonth(inidrillDate.getMonth());
var DateinidrillDate = inidrillDate.getDate();
var MonthinidrillDate = inidrillDate.getMonth();
var YearinidrillDate = inidrillDate.getFullYear();
var findrillDate = inidrillDate;
findrillDate.setMonth(findrillDate.getMonth() + 1);
findrillDate.setDate(findrillDate.getDate() - 1);
var DatefindrillDate = findrillDate.getDate();
var MonthfindrillDate = findrillDate.getMonth();
var YearfindrillDate = findrillDate.getFullYear();
console.log(Date.UTC(
YearinidrillDate,
MonthinidrillDate,
DateinidrillDate
))
console.log(Date.UTC(
YearfindrillDate,
MonthfindrillDate,
DatefindrillDate
))
charts_this.xAxis[0].setExtremes(
Date.UTC(
YearinidrillDate,
MonthinidrillDate,
DateinidrillDate
),
Date.UTC(
YearfindrillDate,
MonthfindrillDate,
DatefindrillDate
)
);
if (charts_this.yAxis[0].dataMax === 0) {
charts_this.yAxis[0].setExtremes(null, 1);
}
}, 0);
}
}
},
title: {
text: '<p className="energy_gen">Energy Generated</p>'
},
exporting: { enabled: false },
xAxis: {
type: "datetime",
labels: {
step: 1
},
dateTimeLabelFormats: {
day: "%e"
}
},
yAxis: {
title: {
text: "kWh"
}
},
credits: {
enabled: false
},
plotOptions: {
series: {
cursor: "pointer",
dataLabels: {
enabled: true,
format: "{point.y}"
},
color: "#fcd562",
point:{
events:{
click:function(event){
}
}
}
}
}
},
tooltip: {
formatter: function() {
if (this.point.options.drilldown) {
return (
"Energy generated: <b> " +
this.y +
"</b> kWh " +
"<br>" +
Highcharts.dateFormat("%b %Y", new Date(this.x))
);
} else {
return (
"Energy generated: <b> " +
this.y +
"</b> kWh " +
"<br>" +
Highcharts.dateFormat("%e %b %Y", new Date(this.x))
);
}
}
},
series: [{'data':obj.data,'name':obj.name,"color":"#4848d3"}],
drilldown: {
series: obj.data
}
});
Also, attaching the screenshot of the rendered highchart with drilldown.
,
Now drilldown graph(same sort a issue)
EDIT:
It turnsout to be a zoom issue, i.e if i zoomout enough, then it shows all points. So, how to show every point without zooimg out .
Working fiddle:
http://jsfiddle.net/gkumar77/w9ngp63u/5/
Use tickInterval property and set it to one month:
xAxis: {
type: "datetime",
tickInterval: 30 * 24 * 3600 * 1000,
labels: {
step: 1
},
dateTimeLabelFormats: {
day: "%e"
}
}
Live demo: http://jsfiddle.net/BlackLabel/q5coany2/
API: https://api.highcharts.com/highcharts/xAxis.tickInterval

HighChart is not working with multiple axis

I want to construct multiple y-axis spline Highchart, but I am getting Null in series.
When I use data manually so it works fine, but When I fetch data from URL it does not work. Also, I am going to prepare a function for creating multiple y-axes.
Can anyone please help me where I am wrong?
Here is my code
<script type="text/javascript">
var axisdata = [{url:"",text:"", yAxis: 1, scrollbar: true,type: "spline"},
{url:"", text:"", yAxix: 2, scrollbar:true, type: "spline"}];
var HighChartObj = {
title: {
text: 'Exchange Rates'
},
scrollbar: {
enabled: true,
showFull: false
},
yAxis: [],
series: [],
rangeSelector: {
selected: 1,
buttonTheme: {
visibility: 'hidden'
},
labelStyle: {
visibility: 'hidden'
},
inputDateFormat: '%H:%M:%S.%L'
},
};
function a(){
var defer = $.Deferred();
z = -1;
var axisLength = axisdata.length - 1;
jQuery.each(axisdata, function(key, value){
$.getJSON( value.url, function (data) {
var dataLength = data.length,
i = 0;
minValue = data[0].open;
maxValue = data[0].open;
var finalData = [];
var new_from_date = 0;
var new_to_date = 0;
var minValue;
var maxValue;
for (i; i < dataLength; i += 1) {
if(i == (dataLength + 99 - dataLength)){
new_to_date = (data[i].start*1000);
}
finalData.push([
(data[i].start*1000),
data[i].open,
]);
if (data[i].open < minValue) {
minValue = data[i].open;
}
else{
if(data[i].open > maxValue){
maxValue = data[i].open;
}
}
}
HighChartObj.xAxis = {
type: 'datetime',
min: new_from_date,
max: new_to_date,
range: new_to_date - new_from_date,
ordinal: false,
endOnTick: false,
startOnTick: false
};
z++;
HighChartObj.yAxis[z] = {
title: {
text: value.text
},
opposite: true,
min: minValue,
max: maxValue,
height: "100%",
scrollbar: {
enabled: value.scrollbar
}
};
var series = {
"type": value.type,
"name": value.text,
"yAxis": value.yAxis,
"id": value.text.toLowerCase().replace(' ', ''),
"zIndex": 1,
"data": finalData
};
if(HighChartObj.series == null){
HighChartObj.series = new Array();
}
HighChartObj.series[z] = series;
if(key == axisLength){
defer.resolve();
}
});
});
return defer.promise();
}
function b(){
// console.log(HighChartObj.series = HighChartObj.test);
console.log(HighChartObj);
Highcharts.stockChart('container', HighChartObj);
}
$.when(a()).then(b());
</script>
Try fetching data like this. Please data in different variables and then pass it to HighChart Object.
function a(){
z = -1;
var axisLength = axisdata.length - 1;
var dataSeries = new Array()
var dataYaxis = new Array();
jQuery.each(axisdata, function(key, value){
var axisValue = value;
$.ajax({
dataType: "json",
url: axisValue.url,
success: function (data) {
var dataLength = data.length,
i = 0;
minValue = data[0].open;
maxValue = data[0].open;
var finalData = [];
var new_from_date = 0;
var new_to_date = 0;
var minValue;
var maxValue;
for (i; i < dataLength; i += 1) {
if(i == (dataLength + 99 - dataLength)){
new_to_date = (data[i].start*1000);
}
var date = (data[i].start*1000);
finalData.push([
date,
data[i].open,
]);
if (data[i].open < minValue) {
minValue = data[i].open;
}
else{
if(data[i].open > maxValue){
maxValue = data[i].open;
}
}
}
z++;
HighChartObj.xAxis = {
type: 'datetime',
min: new_from_date,
max: new_to_date,
range: new_to_date - new_from_date,
ordinal: false,
endOnTick: false,
startOnTick: false
};
var yAxis = {
title: {
text: axisValue.text
},
opposite: false,
min: minValue,
max: maxValue,
height: "100%",
scrollbar: {
enabled: axisValue.scrollbar
}
};
dataYaxis.push(yAxis);
var series = {
type: axisValue.type,
name: axisValue.text,
id: axisValue.text.toLowerCase().replace(' ', ''),
zIndex: 2,
data: finalData
};
dataSeries.push(series);
if(key == axisLength){
HighChartObj.yAxis = dataYaxis;
HighChartObj.series = dataSeries;
b();
}
}
});
});
}

Memory leak problems for column chart

I am not good at speaking English. Please understand.
I'm having a memory leak problem when using the stack column chart.
We update the data using setCategories, setData on a stack column chart every 2 seconds.
But, the memory usage continues to increase and the browser will be forcibly terminated.
The only thing that program does is call setCategories, setData. Is there anything I need to do to clean up the memory?
The test environment is os: windows7, windows10, browser: lastest version chrome 57.0.2987.133
you can see that you keep increasing after 1, 3, 5, 7, 10, 15, and 20 minutes.
Memory usage increases with time, so you can check it immediately.
You can check memory usage in the task window by running [shift + esc] shortcut in Chrome.
Send the sample code as an attachment. Thank you.
JQuery and Highcharts(5.0.10) use the latest version.
<script>
var dy = {
instanceAlias : {}
};
var CATEGORIES = ["a1","a2","a3","a4","a5","a6","a7","a8","a9","a10","a11","a12","a13","a14","a15","a16","a17","a18","a19","a20"];
var THEME = "";
var HEIGHT = "290";
var highchartConfig = {
column : {
chart: {
renderTo: null,
type: 'column'
},
xAxis: {
gridLineWidth: 1,
tickLength: 4,
categories : null,
labels : {
rotation: 0,
formatter : function(d){
return dy.instanceAlias[this.value] || this.value;
}
}
},
yAxis: {
min : 0,
max : 5,
lineWidth: 1,
tickLength: 4, // Same value as offset
tickPosition: "outside",
tickWidth: 1,
tickAmount: 3,
tickInterval : 25,
title: {
style : {
display: 'none'
}
},
stackLabels: {
style : {
"fontWeight": "normal",
color : (THEME == "dark") ? "#b0b0b3" : "#000"
}
}
},
plotOptions: {
series: {
borderRadius: 6,
borderWidth: 0,
marker :{
enabled :true,
symbol : "circle",
radius : 4
}
}
},
series: null
}
};
var stack1Config = $.extend(true,{},highchartConfig.column,{
colors : ["#009651","#ff9800","#ff1100","#009651"], //stack colors
chart: {
animation: false,
renderTo: "stack1",
height : HEIGHT
},
xAxis: {
categories : CATEGORIES
},
title: {
style: {
display: 'none'
}
},
subtitle: {
style: {
display: 'none'
}
},
legend : false,
tooltip : false,
yAxis: {
max : null,
tickInterval : null,
tickLength : null,
stackLabels: {
enabled: true,
useHTML : false,
style : {
"fontWeight": "normal",
color : (THEME == "dark") ? "#b0b0b3" : "#000"
}
}
},
plotOptions: {
column: {
stacking: 'normal',
},
series: {
animation: false,
stickyTracking: false,
enableMouseTracking: false,
lineWidth: 0,
marker: {
enabled : true,
symbol : "circle",
radius : 4
},
}
},
series : (function(){
var series = new Array();
var stack = [
{id : "normal", alias : "normal"},
{id : "warning", alias : "warning"},
{id : "danger", alias : "danger"}
];
for (var i = 0; i < stack.length; i++) {
//stack column 브러시 추가.
series.push({
name : stack[i].alias || stack[i].id,
id : stack[i].id,
lineWidth: 1,
data : (function(categories){
var data = [];
for (var i = 0; i < categories.length; i++) {
data.push(0);
}
return data;
})(CATEGORIES)
});
}
//circle
series.push({
type : "scatter",
name : "scatter",
id : "scatter",
marker: {
fillColor: '#FFFFFF',
lineWidth: 1,
lineColor: null
},
data : (function(b){
var data = [];
for (var i = 0; i < b.length; i++) {
data.push(0);
}
return data;
})(CATEGORIES)
});
console.log(series)
return series;
})()
});
var stack2Config = $.extend(true,{},highchartConfig.column,{
colors :["#009651"],
chart: {
animation: false,
renderTo: "stack2",
height : HEIGHT
},
xAxis: {
categories : CATEGORIES
},
title: {
style: {
display: 'none'
}
},
subtitle: {
style: {
display: 'none'
}
},
legend : false,
tooltip : false,
yAxis: {
max : null,
tickInterval : null,
tickLength : null,
stackLabels: {
enabled: true,
useHTML : false,
style : {
"fontWeight": "normal",
color : (THEME == "dark") ? "#b0b0b3" : "#000"
}
}
},
plotOptions: {
animation: false,
stickyTracking: false,
enableMouseTracking: false,
lineWidth: 0,
marker : {
enabled : false
},
column : {
dataLabels: {
enabled: true,
useHTML: true,
x : 0,
y : 0,
style : {
"fontWeight": "normal"
}
}
}
},
series : (function(){
var series = new Array();
var stack = [
{id : "cpu", alias : "CPU"}
];
for (var i = 0; i < stack.length; i++) {
//stack column 브러시 추가.
series.push({
name : stack[i].alias || stack[i].id,
id : stack[i].id,
lineWidth: 1,
data : (function(categories){
var data = [];
for (var i = 0; i < categories.length; i++) {
data.push(0);
}
return data;
})(CATEGORIES)
});
}
//circle
series.push({
type : "scatter",
name : "scatter",
id : "scatter",
marker: {
fillColor: '#FFFFFF',
lineWidth: 1,
lineColor: null
},
data : (function(b){
var data = [];
for (var i = 0; i < b.length; i++) {
data.push(0);
}
return data;
})(CATEGORIES)
});
console.log(series)
return series;
})()
});
var stack1 = Highcharts.chart(stack1Config);
var stack2 = Highcharts.chart(stack2Config);
var alarmTimeoutId = null;
var alarmTimeout = function(){
return setTimeout(function(){
var ACT_COLUMN = {
normal : [],
warning : [],
danger : [],
scatter : [] // success,warning,danger total value
};
var length = 20;
for (var i = 0; i < length; i++) {
var normalCnt = Math.round(Math.random()*100);
var warningCnt = Math.round(Math.random()*100);
var dangerCnt = Math.round(Math.random()*100);
ACT_COLUMN.scatter.push({ y: normalCnt+warningCnt+dangerCnt });
ACT_COLUMN.normal.push(normalCnt);
ACT_COLUMN.warning.push(warningCnt);
ACT_COLUMN.danger.push(dangerCnt);
}
for (var key in ACT_COLUMN) {
stack1.get(key).setData(ACT_COLUMN[key],false,false);
}
stack1.xAxis[0].setCategories(CATEGORIES);
ACT_COLUMN.scatter = null;
ACT_COLUMN.normal = null;
ACT_COLUMN.warning = null;
ACT_COLUMN.danger = null;
ACT_COLUMN = null;
var cpuData = [];
for (var i = 0; i < length; i++) {
var cpu = Math.round(Math.random()*100);
var color = "#009651";
if(cpu <= 50){
color = "#009651";
}else if(cpu <= 80){
color = "#ff9800";
}else{
color = "#ff1100";
}
cpuData.push({y : cpu, color : color });
}
var series = stack2.series;
var seriesLength = series.length;
for (var i = 0; i < seriesLength; i++) {
series[i].setData(cpuData,false,false);
}
stack2.xAxis[0].setCategories(CATEGORIES);
clearTimeout(alarmTimeoutId);
alarmTimeoutId = alarmTimeout();
}, 2000);
}
alarmTimeout();
</script>

Resources