hightchats调用数据问题,急急急
hightcharts的data在页面调用只可以是实际的数吗?
代码如下:
$(function () {
$('#container3').highcharts({
chart: {
type: 'gauge',
plotBorderWidth: 1,
plotBackgroundColor: {
linearGradient: { x1: 0, y1: 0, x2: 0, y2: 1 },
stops: [
[0, '#FFF4C6'],
[0.3, '#FFFFFF'],
[1, '#FFF4C6']
]
},
plotBackgroundImage: null,
height:165
},
title: {
text: '温度'
},
pane: [{
startAngle: -45,
endAngle: 45,
background: null,
center: ['50%', '105%'],
size: 200
}],
yAxis: [{
min: -50,
max: 50,
minorTickPosition: 'outside',
tickPosition: 'outside',
labels: {
rotation: 'auto',
distance: 20
},
plotBands: [{
from: 30,
to: 50,
color: '#C02316',
innerRadius: '100%',
outerRadius: '105%'
}],
pane: 0,
title: {
text: 'C<br/><span style="font-size:8px"></span>',
y: -20
}
}],
plotOptions: {
gauge: {
dataLabels: {
enabled: false
},
dial: {
radius: '100%'
}
}
},
series: [{
data: [-20],//此处的-20能否改为变量,经过多次试验发现不可以,
//请教过身边的人,说是页面部分传的是String型的变量
//而非整型的。问题1、有没有可以将String型变为整型的
//方法。2、可以从后台调用数据,发送到页面吗?代码怎样写?请大神帮助。
yAxis: 0
}]
},
// Let the music play
function(chart) {
setInterval(function() {
var left = chart.series[0].points[0],
leftVal,
inc = (Math.random() - 0.5) * 6;
leftVal = left.y + inc;
if (leftVal < -20 || leftVal > 6) {
leftVal = left.y - inc;
}
left.update(leftVal, false);
chart.redraw();
}, 500);
});
});
</script> highcharts javaWeb
急急急!
[解决办法]
JS里定义个全局变量,ajax调用数据,得到的数据赋值给变量,然后highcharts 那个data直接用那个变量
tooltip: {
headerFormat: '<span style="font-size:10px">{point.key}流量统计</span><table>',
pointFormat: '<tr><td style="color:{series.color};padding:0">{series.name}: </td>' +
'<td style="padding:0"><b>{point.y} MB</b></td></tr>',
footerFormat: '</table>',
shared: true,
useHTML: true
},
plotOptions: {
column: {
pointPadding: 0.2,
borderWidth: 0
}
},
series: [{
name: date1,
data: flowDataYAxis1
}, {
name: date2,
data: flowDataYAxis2
}]
});