highcharts+.net+mssql做柱状图,后台数据怎么绑定就可以查询到数据库查询结果

[复制链接]
查看11 | 回复8 | 2021-1-27 07:19:33 | 显示全部楼层 |阅读模式


==========================
前台和后台怎么写,就可以查询到数据库的数据了。
分 -->
回复

使用道具 举报

千问 | 2021-1-27 07:19:33 | 显示全部楼层



回复

使用道具 举报

千问 | 2021-1-27 07:19:33 | 显示全部楼层
查出来的数据做成控件接受的格式
回复

使用道具 举报

千问 | 2021-1-27 07:19:33 | 显示全部楼层
引用2楼FoxDave的回复:查出来的数据做成控件接受的格式可否说具体一点呢?
回复

使用道具 举报

千问 | 2021-1-27 07:19:33 | 显示全部楼层
巧了,我刚刚弄好这一块。。。
回复

使用道具 举报

千问 | 2021-1-27 07:19:33 | 显示全部楼层
首先,我创建了一个类,用来序列化成json格式用的,然后传递给前台用的(我这里是mvc的,所以最后直接returnJson(ReportData)就可以了,如果你是webform那么你需要newtonsoft.dll
publicclassReportData
{
publicstring[]categories{get;set;}
publicListReportItems=newList();
}
publicclassReportItem
{
publicstringname{get;set;}
publicdecimal?[]data{get;set;}
publicbool?sliced{get;set;}
publicbool?selected{get;set;}
publicdecimal?y{get;set;}
}
你的这个图,我也正好用了。
然后是去查询数据
publicReportDataGetReprotData_Month(intWD_ProductSite_Id,DateTime?beginTime,DateTime?endTime)
{
//查询数据我就不贴出来了。q就是查询到的数据
ReportDatareportData=newReportData();
reportData.categories=q.Select(x=>x.createMonth).ToArray();
ReportItemri1=newReportItem()
{data=q.Select(x=>x.AgentUsed).ToArray(),name="AgentUsed",selected=true,sliced=true};
reportData.ReportItems.Add(ri1);
ReportItemri2=newReportItem()
{data=q.Select(x=>x.Emission).ToArray(),name="Emission"};
reportData.ReportItems.Add(ri2);

returnreportData;
}
这里是数据库通过存储过程,查询出的数据格式


前台绑定:
pie-legend

ajax方法:
$.ajax({
url:"IndexGetReportData_Month",
type:"post",
success:function(data){
columnBasic(data.categories,data.ReportItems);
}
});
//column-basic
functioncolumnBasic(categories,series)
{
$('#container').highcharts({
chart:{
type:'column'
},
title:{
text:'MonthlyAverageRainfall'
},
subtitle:{
text:'Source:WorldClimate.com'
},
xAxis:{
categories:categories,
crosshair:true
},
yAxis:{
min:0,
title:{
text:'Rainfall(mm)'
}
},
tooltip:{
headerFormat:'{point.key}',
pointFormat:'{series.name}:'+
'{point.y:.1f}mm',
footerFormat:'',
shared:true,
useHTML:true
},
plotOptions:{
column:{
pointPadding:0.2,
borderWidth:0
}
},
series:series
});
}

最后看一下效果


回复

使用道具 举报

千问 | 2021-1-27 07:19:33 | 显示全部楼层
#container打错了,应该是#container1额。。。


回复

使用道具 举报

千问 | 2021-1-27 07:19:33 | 显示全部楼层
引用5楼hanjun0612的回复:首先,我创建了一个类,用来序列化成json格式用的,然后传递给前台用的(我这里是mvc的,所以最后直接returnJson(ReportData)就可以了,如果你是webform那么你需要newtonsoft.dll
publicclassReportData
{
publicstring[]categories{get;set;}
publicListReportItems=newList();
}
publicclassReportItem
{
publicstringname{get;set;}
publicdecimal?[]data{get;set;}
publicbool?sliced{get;set;}
publicbool?selected{get;set;}
publicdecimal?y{get;set;}
}
你的这个图,我也正好用了。
然后是去查询数据
publicReportDataGetReprotData_Month(intWD_ProductSite_Id,DateTime?beginTime,DateTime?endTime)
{
//查询数据我就不贴出来了。q就是查询到的数据
ReportDatareportData=newReportData();
reportData.categories=q.Select(x=>x.createMonth).ToArray();
ReportItemri1=newReportItem()
{data=q.Select(x=>x.AgentUsed).ToArray(),name="AgentUsed",selected=true,sliced=true};
reportData.ReportItems.Add(ri1);
ReportItemri2=newReportItem()
{data=q.Select(x=>x.Emission).ToArray(),name="Emission"};
reportData.ReportItems.Add(ri2);

returnreportData;
}
这里是数据库通过存储过程,查询出的数据格式


前台绑定:
pie-legend

ajax方法:
$.ajax({
url:"IndexGetReportData_Month",
type:"post",
success:function(data){
columnBasic(data.categories,data.ReportItems);
}
});
//column-basic
functioncolumnBasic(categories,series)
{
$('#container').highcharts({
chart:{
type:'column'
},
title:{
text:'MonthlyAverageRainfall'
},
subtitle:{
text:'Source:WorldClimate.com'
},
xAxis:{
categories:categories,
crosshair:true
},
yAxis:{
min:0,
title:{
text:'Rainfall(mm)'
}
},
tooltip:{
headerFormat:'{point.key}',
pointFormat:'{series.name}:'+
'{point.y:.1f}mm',
footerFormat:'',
shared:true,
useHTML:true
},
plotOptions:{
column:{
pointPadding:0.2,
borderWidth:0
}
},
series:series
});
}

最后看一下效果

看下你的私信我给你发了一条私信还有些这方面的问题请教一下你
回复

使用道具 举报

千问 | 2021-1-27 07:19:33 | 显示全部楼层
我也想知道怎么弄的最近一直在找这个
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行