HighCharts动态显示数据实例
2013-09-13 17:01
561 查看
<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: 'helloweba.com'
},
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 ;
}
}
}
},
series: [{ //数据列
name: 'search engine',
data: [{"name":"\u767e\u5ea6","y":1239,"sliced":true,"selected":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,"selected":true},["google",google],["\u641c\u641c",342],["\u5fc5\u5e94",421],["\u641c\u72d7",259],["\u5176\u4ed6",83]];
chart.series[0].setData(data);
}
setInterval(changeData,1000);
});
//保留2位小数
function twoDecimal(x) {
var f_x = parseFloat(x);
if (isNaN(f_x)) {
alert('错误的参数');
return false;
}
var f_x = Math.round(x * 100) / 100;
var s_x = f_x.toString();
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>
var chart;
$(function() {
chart = new Highcharts.Chart({
chart: {
renderTo: 'chart_pie', //饼状图关联html元素id值
defaultSeriesType: 'pie', //默认图表类型为饼状图
plotBackgroundColor: '#ffc', //设置图表区背景色
plotShadow: true //设置阴影
},
title: {
text: '搜索引擎统计分析' //图表标题
},
credits: {
text: 'helloweba.com'
},
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 ;
}
}
}
},
series: [{ //数据列
name: 'search engine',
data: [{"name":"\u767e\u5ea6","y":1239,"sliced":true,"selected":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,"selected":true},["google",google],["\u641c\u641c",342],["\u5fc5\u5e94",421],["\u641c\u72d7",259],["\u5176\u4ed6",83]];
chart.series[0].setData(data);
}
setInterval(changeData,1000);
});
//保留2位小数
function twoDecimal(x) {
var f_x = parseFloat(x);
if (isNaN(f_x)) {
alert('错误的参数');
return false;
}
var f_x = Math.round(x * 100) / 100;
var s_x = f_x.toString();
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>
相关文章推荐
- Highcharts结合Asp.net实现动态数据股票式图形显示实例
- Highcharts结合Asp.net实现动态数据股票式图形显示实例
- Highcharts结合Asp.net实现动态数据股票式图形显示实例 .【转】
- Highcharts、AJAX、JSON、JQuery实现动态数据交互显示图表柱形图
- Highcharts数据提示框动态显示非x轴非y轴数据
- highcharts 柱状图动态设置数据应用实例
- highcharts在J2EE中绘制柱状图实例(从后台获取动态数据)
- Highcharts数据提示框动态显示非x轴非y轴数据
- 动态绘圆根据接收数据实时显示_在后台绘图显示实例
- Django向Highcharts图表发送数据并用模板语言实现动态显示
- jquery结合highcharts插件显示实时数据动态曲线图
- highcharts实例和json数据显示
- python处理csv数据动态显示曲线实例代码
- HighCharts实现多数据折线图分列显示
- CTreeCtrl使用CToolTipCtrl(设置有换行、延迟、显示数据动态切换)
- Android 根据EditText搜索框ListView动态显示数据
- jQuery easyUI动态获取表结构并显示表中的数据)
- HighCharts动态读取显示
- $,ajxa动态获取数据表格显示
- MathJax显示动态数据问题