highcharts使用之使用数组数据绑定数据
2017-09-13 14:01
330 查看
highcharts的官方API的例子(例子地址:https://code.hcharts.cn/highcharts/d5J8om)中,数组的使用:
然后用这个dataArray代替rows的值即可,如:data: { rows: dataArray}
完整的代码:
data: { rows: [ [null, '小明', '小红','sdsa'], // 第一行为数据列的名字 ['苹果', 1, 5,1], // 分类及数值 ['梨', 4, 4,5], // 分类及数值 ['橙子', 3, 2,6] // 分类及数值 ] }首先,需要定义一个数据数组。
var dataArray = new Array();
dataArray[0] = [null, '苹果', '橘子', '梨', '西瓜'];其中,数组中又是一个数组,其中dataArray数组中的第一个元素时数据列的名字,即:legend(图例)的名字
然后用这个dataArray代替rows的值即可,如:data: { rows: dataArray}
完整的代码:
$.getJSON('/Report/Sel?', function (data) { var recharge_count = 0, active_count = 0, recharge_rate = 0; //var str = '<tbody>'; var dataArray = new Array(); dataArray[0] = [null, '苹果', '橘子', '梨', '西瓜']; $.each(data, function (infoIndex, info) { if (info["active_count"] != "") active_count = parseFloat(info["active_count"]); else active_count = 0; if (info["recharge_count"] != "") recharge_count = parseFloat(info["recharge_count"]); else recharge_count = 0; if (info["recharge_rate"] != "") recharge_rate = parseFloat(info["recharge_rate"]); else recharge_rate = 0; dataArray[infoIndex + 1] = ['', active_count, recharge_count, recharge_rate, info["goal"]]; }) //用数据生成图形数据 Highcharts.chart('container', { chart: { type: 'line', zoomType: 'xy', backgroundColor: '#34445e' }, title: { text: '水果价格', style: { color: '#fff', fontSize: "25px", fontWeight: "bold", } }, xAxis: { crosshair: true, lineColor: '', labels: { style: { color: '#a9b5c2', fontSize: '20px' } } }, tooltip: { shared: true }, yAxis: [ //右Y轴 { min: 0, max: 100, alignTicks: false, gridLineWidth: 0, title: { text: null,/*style: {color: Highcharts.getOptions().colors[0]}*/ }, labels: { format: null, style: { color: '#a9b5c2' }, format: '{value} %', }, opposite: true }, //左Y轴 { min: 0, labels: { format: null, style: { color: '#a9b5c2' } }, title: { text: null,/*style: {color: Highcharts.getOptions().colors[1]}*/ } }], plotOptions: { column: { dataLabels: { enabled: true, style: { color: '#D7DEE9' }, y: 20 } }, line: { dataLabels: { enabled: true, style: { color: '#D7DEE9' }, // 折线数据显示% formatter: function () { return this.point.y + '%'; } }, tooltip: { valueSuffix: '%' }, //点形状 marker: { radius: 5, symbol: 'circle' }, } }, colors: ['#2ea7e1', '#f5e766', '#ed1c24'], data: { rows: dataArray }, });
相关文章推荐
- Highcharts 的使用(各种统计图)(难点:绑定数据)
- 使用Repeater实现自定义多列数据绑定
- *数组的数据系结DataList 绑定数组到DataList*
- 数据绑定(Databind)与 repeater 控件的使用。
- JST+JSON+AJAX——使用客户端js模版代替服务端数据绑定
- .net学习_使用databinder进行数据绑定20060525
- 使用标准数据绑定语法代替 DataBinder.Eval 方法以提高性能
- 如何使用 DataBinder.Eval(Container.DataItem,"num","{0:p}") 对DataList 进行数据绑定
- 如何使用DataBinder.Eval()方法进行数据绑定
- 关于数据绑定,还有DropDownList和DATAGRID的使用
- 关于使用asp.net 的分页显示数据。Repeater绑定数据后的分页显示。
- 解决Eval()、XPath() 和 Bind() 这类数据绑定方法只能在数据绑定控件的上下文中使用
- Effective C# 原则38:使用和支持数据绑定(译)
- JST+JSON+AJAX——使用客户端js模版代替服务端数据绑定
- (转贴)使用Repeater实现自定义多列数据绑定
- 老鼠Atlas之旅(九):Hands-On Lab 5第五个实验,使用数据绑定和模板创建个Atlas应用程序
- 如何解决FormView中实现DropDownList连动选择时出现 "Eval()、XPath() 和 Bind() 这类数据绑定方法只能在数据绑定控件的上下文中使用" 的错误
- 使用自定义的数据源进行DataGrid控件的数据绑定
- 使用数据绑定实现多窗口间的数据同步
- 如何使用DataBinder.Eval()方法进行数据绑定