您好,欢迎访问一九零五行业门户网

(四)、读取数据库数据并在HighCharts上显示

x轴: xaxis: { categories: ['周一', '周二', '周三', '周四', '周五', '周六', '周日' ], //x轴的坐标值 title: {text: '周数'}, //x轴坐标标题 } y轴: yaxis: { title: {text: '人数(人)'}, //y轴坐标标题 } 主标题: title: { text: '图表主标题' }, //
x轴:
     xaxis: {
                    categories: ['周一', '周二', '周三', '周四', '周五', '周六', '周日' ], //x轴的坐标值
                    title: {text: '周数'},  //x轴坐标标题
                }
y轴:
     yaxis: {
                    title: {text: '人数(人)'},  //y轴坐标标题
                }
主标题:
     title: { text: '图表主标题' }, //图表主标题
副标题:
     subtitle: {text: '图表子标题' }, //图表副标题
y轴数据:
     series:[{ name: '人数', data: [20, 40, 30, 90, 100, 60, 50] }]
这些值我们都可以从数据库获得数据,然后动态绑定上去即可,这里后台代码中最常用的是stringbuilder,通过它来拼凑出要绑定的数据
x轴:
     xaxis: {
                    categories: , //x轴的坐标值
                    title: ,  //x轴坐标标题
                }
y轴:
     yaxis: {
                    title:,  //y轴坐标标题
                }
主标题:
     title: , //图表主标题
副标题:
     subtitle: , //图表副标题
y轴数据:
     series:
下面给出获取x轴、y轴、标题的方法:
public string xaxiscategories = ; //x轴
    public stringbuilder seriesdata = new stringbuilder(); //y轴
    public string title = ; // 图表标题
    ...
  标题获取
title = {text: ' + +site_name ++'};  //红色标记的部分是从数据库动态获取的,怎么获取,该获取什么,根据你需要,你应该懂的
x轴获取:
stringbuilder xaxiscategories = new stringbuilder();
xaxiscategories.append([);
...
foreach (datarowview drv in ds.tables[0].defaultview)
{
     xaxiscategories.append(');
     xaxiscategories.append(drv[周数] == null ? 0 : drv[周数].tostring());
     xaxiscategories.append(',);
}
xaxiscategories = xaxiscategories.replace(,, , xaxiscategories.length - 1, 1).append(]).tostring(); //这里是去掉最后一个多余的逗号(,)
y轴获取:
stringbuilder yaxiscategories = new stringbuilder();
...
foreach (datarowview drv in ds.tables[0].defaultview)
{
     yaxiscategories.append(drv[人数] == null ? 0 : drv[人数].tostring());
     yaxiscategories.append(,);
}
seriesdata.append([{name: '人数',type: 'spline',data: [);
seriesdata.append(yaxiscategories.replace(,, , yaxiscategories.length - 1, 1)); //去除最后一个逗号(,)
seriesdata.append(]}]);
其它类似信息

推荐信息