HighCharts动态显⽰数据实例
<script type="text/javascript">
var chart;
$(function() {
chart = new Highcharts.Chart({
chart: {
我欲与君相知
renderTo: 'chart_pie', //饼状图关联html元素id值
defaultSeriesType: 'pie', //默认图表类型为饼状图
plotBackgroundColor: '#ffc', //设置图表区背景⾊
plotShadow: true //设置阴影
},
title: {
text: '搜索引擎统计分析' //图表标题
},
credits: {荒僻
text: ''
},
tooltip: {
formatter: function() { //⿏标滑向图像提⽰框的格式化提⽰信息
return '<b>' + this.point.name + '</b>: ' + twoDecimal(this.percentage) + ' %';
}
},
plotOptions: {
pie: {
allowPointSelect: true, //允许选中,点击选中的扇形区可以分离出来显⽰
尖椒炒肥肠的做法cursor: 'pointer', //当⿏标指向扇形区时变为⼿型(可点击)
//showInLegend: true, //如果要显⽰图例,可将该项设置为true
dataLabels: {
enabled: true, //设置数据标签可见,即显⽰每个扇形区对应的数据
color: '#000000', //数据显⽰颜⾊
connectorColor: '#999', //设置数据域扇形区的连接线的颜⾊
祝女儿生日的内涵句子style:{寻梦环游记海报
fontSize: '12px' //数据显⽰的⼤⼩
},
formatter: function() { //格式化数据
return '<b>' + this.point.name + '</b>: ' + twoDecimal(this.percentage) + ' %';
//return '<b>' + this.point.name + '</b>: ' + this.y ;
}
}
}
},
ries: [{ //数据列
name: 'arch engine',
data: [{"name":"\u767e\u5ea6","y":1239,"sliced":true,"lected":true},["google",998],["\u641c\u641c",342],
["\u5fc5\u5e94",421],["\u641c\u72d7",259],["\u5176\u4ed6",83]] //核⼼数据列来源于php读取的数据并解析成JSON }]
});
function changeData(){
var baidu= Math.floor(Math.random()*10000+1);
莫泊桑项链var google = Math.floor(Math.random()*10000+1);
var data = [{"name":"\u767e\u5ea6","y":baidu,"sliced":true,"lected":true},["google",google],["\u641c\u641c",342], ["\u5fc5\u5e94",421],["\u641c\u72d7",259],["\u5176\u4ed6",83]];
chart.ries[0].tData(data);
}
tInterval(changeData,1000);
});gequ
//保留2位⼩数
function twoDecimal(x) {
var f_x = parFloat(x);
if (isNaN(f_x)) {
alert('错误的参数');
return fal;
}
var f_x = und(x * 100) / 100; var s_x = String();
var pos_decimal = s_x.indexOf('.');小学生科技小制作
if (pos_decimal < 0) {
pos_decimal = s_x.length;
s_x += '.';
}
while (s_x.length <= pos_decimal + 2) { s_x += '0';
}
return s_x;
}
</script>