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>
Related
Below are my questions
I am using advanced accessible chart in high charts and I have customized few data points to be circle . Since the data for these points is almost in the same range , it's causing the data points to overlap . How do I prevent this?
the tooltip provided for these customized data points(circle) are not showing up . How to get the tool tip displayed.
I have been pondering a lot but none of the solution is working . Any help is appreciated.
Thanks.
enter image description here
function DrawRemoteRequestPSRChart(seriesData, yAxisCategories) {
Highcharts.seriesType('lowmedhigh', 'boxplot', {
keys: ['low', 'high'],
}, {
drawPoints: function () {
var series = this;
this.points.forEach(function (point) {
var graphic = point.graphic,
verb = graphic ? 'animate' : 'attr',
shapeArgs = point.shapeArgs,
width = 0,
left = Math.floor(shapeArgs.x) + 0.5,
right = left + width,
crispX = left + Math.round(width / 2) + 0.5,
highPlot = Math.floor(point.highPlot) + 0.5,
lowPlot = Math.floor(point.lowPlot) +
0.5 - (point.low === 0 ? 1 : 0);
if (point.low == point.high) {
highPlot = lowPlot - 20;
}
else if (lowPlot - highPlot < 20) {
highPlot = lowPlot - 20;
}
if (point.isNull) {
return;
}
if (!graphic) {
point.graphic = graphic = series.chart.renderer
.path('point')
.add(series.group);
} else {
console.log('graphic');
}
if (Math.floor(point.lowPlot) == Math.floor(point.highPlot)) {
graphic.attr({
stroke: "#FFCD11",
"stroke-width": 2,
});
//console.log('point.lowPlot & highplot ' + point.lowPlot, point.highPlot )
}
else {
graphic.attr({
stroke: "lime",
"stroke-width": 4,
"borderColor": "black"
});
}
graphic[verb]({
d: [
'M', left, highPlot,
'H', right,
'M', left, lowPlot,
'H', right,
'M', crispX, highPlot,
'V', lowPlot
]
});
});
}
});
var chart = Highcharts.chart('GraphHere', {
chart: {
type: 'lowmedhigh',
inverted: true,
},
credits: {
enabled: false
}, legend: {
enabled: false
},
title: {
text: ''
},
tooltip: {
useHTML: true,
shared: false,
formatter: function () {
if (this.point.options.low != this.point.options.high) {
return this.point.category + ': <br>PSR Request Time: ' + new Date(this.point.options.low).toGMTString() +
' <br>PSR Received Time: ' + new Date(this.point.options.high).toGMTString();
} else {
return this.point.category + ': <br>PSR Request Time: ' + new Date(this.point.options.low).toGMTString() +
' <br>PSR Received Time: N/A';
}
},
pointFormatter: function () {
if (this.point.options.low != this.point.options.high) {
return this.point.category + ': <br>PSR Request Time: ' + new Date(this.point.options.low).toGMTString() +
' <br>PSR Received Time: ' + new Date(this.point.options.high).toGMTString();
} else {
return this.point.category + ': <br>PSR Request Time: ' + new Date(this.point.options.low).toGMTString() +
' <br>PSR Received Time: N/A';
}
}
},
xAxis: [{
categories: yAxisCategories,
crosshair: true,
gridLineWidth: 1,
}],
yAxis: {
type: 'datetime',
gridLineWidth: 0
},
plotOptions: {
column: {
pointWidth: 10
},
series: {
stickyTracking: true,
whiskerWidth: 2,
grouping: true
}
},
series: seriesData
});
var seriesidexlength = chart.series.length;
for (var seriesidex = 0; seriesidex < seriesidexlength; seriesidex++) {
var dataindexlength = chart.series[seriesidex].data.length;
for (var dataindex = 0; dataindex < dataindexlength; dataindex++) {
var fromdate = new Date(chart.series[seriesidex].data[dataindex].low);
var todate = new Date(chart.series[seriesidex].data[dataindex].high);
if (fromdate.getDate() == todate.getDate()) {
//if (chart.series[seriesidex].data[dataindex].low == chart.series[seriesidex].data[dataindex].high) {
if (chart.series[seriesidex].data[dataindex].graphic != undefined) {
var obj = chart.series[seriesidex].data[dataindex].graphic.renderer.symbol('circle', chart.series[seriesidex].data[dataindex].plotX, chart.series[seriesidex].data[dataindex].plotY, 5).attr({ fill: 'orange', pointwidth: 10 }).add(chart.series[seriesidex].group);
chart.series[seriesidex].data[dataindex].graphic.destroy();
chart.series[seriesidex].data[dataindex].graphic = obj;
//console.log("same date - " + chart.series[seriesidex].data[dataindex].plotX, chart.series[seriesidex].data[dataindex].plotY)
} else {
//console.log("undefined"+seriesidex, dataindex)
}
//}
} else {
//console.log("not same" + seriesidex, dataindex)
}
}
}
chart.container.onmousedown = null;
chart.container.onclick = null;
$('.highcharts-yaxis').hide();
}
I've implemented a polar chart in which each series has 4 values corresponding to 4 categories. When I export the chart csv, the category column contains polar coordinates. I would like to replace these with the corresponding category name. How do I do this?
Adding the categories to each series, had no effect. I also tried adding a categories property to the xAxis, but it had not effect. An xAxis.label formatter successfully returns the category name for each data polar coordinate.
const options = {
chart: {
polar: true,
},
title: {
text: '',
},
tooltip: {
valueDecimals: 2,
headerFormat: '<br/>',
},
legend: {},
pane: {
startAngle: 0,
endAngle: 360,
},
xAxis: {
tickInterval: 45,
min: 0,
max: 360,
labels: {
// eslint-disable-next-line
formatter: function() {
switch (this.value) {
case 45:
return '<b>Experience</b>'
case 135:
return '<b>Frictionless</b>'
case 225:
return '<b>Low Price</b>'
case 315:
return '<b>Brand</b>'
default:
return ''
}
},
},
},
yAxis: {
min: 0,
max: 10,
labels: {
format: '{}',
},
},
plotOptions: {
series: {
pointStart: 45,
pointInterval: 90,
},
column: {
pointPadding: 0,
groupPadding: 0,
},
},
series: kahnSeries,
}
You need to use categories property, but without options like: pointInterval, pointStart, min and max:
xAxis: {
categories: ['Experience', 'Frictionless', 'Low Price', 'Brand']
},
Live demo: http://jsfiddle.net/BlackLabel/z8cm1p39/
API Reference: https://api.highcharts.com/highcharts/xAxis.categories
To avoid changing the chart's current display, I wrapped the getCSV function and replaced the CSV category values. If there was a simpler way, please share it.
{
(function (H) {
H.wrap(H.Chart.prototype, 'getCSV', function (
proceed,
useLocalDecimalPoint
) {
// Run the original proceed method
const result = proceed.apply(
this,
Array.prototype.slice.call(arguments, 1)
)
const itemDelimiter = ','
const lineDelimiter = '\n'
const rows = result.split(lineDelimiter)
let newResult = ''
let rowCategories = false
rows.forEach((row, rowIndex) => {
const columns = row.split(itemDelimiter)
if (rowIndex === 0 && columns[0] === '"Category"') {
rowCategories = true
}
if (rowIndex > 0 && rowCategories) {
let newRow = formatter(columns[0])
columns.forEach((column, columnIndex) => {
if (columnIndex > 0) {
newRow += itemDelimiter
newRow += column
}
})
newResult += newRow
} else {
newResult += row
}
if (rowIndex < rows.length - 1) {
newResult += lineDelimiter
}
}
)
return newResult
})
}(Highcharts))
}
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
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();
}
}
});
});
}
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>