本人就是想让柱状图获取的是表内区间的全部数量,例如100-200之间有多少个,就是0-30 31-90 91-180 181-365 365以上,这5个。,这是要获取的表内容。
怎样才可以让这5个柱子分别代表0-30 31-90 91-180 181-365 365以上,的各个数量。现在的柱子是全部的。并没有区间。
底下是代码,求怎么改,
怎样才可以让这5个柱子分别代表0-30 31-90 91-180 181-365 365以上,的各个数量。现在的柱子是全部的。并没有区间。
底下是代码,求怎么改,
public LineChartDataModel<int> GetUkeyChart() { using (var DbContext = new CRBFoundationDbContext()) { var rankSize = 5; LineChartDataModel<int> lineChartDataModel = new LineChartDataModel<int>() { SeriesData = new List<ChartSeries<int>>(), XAxisData = new string[rankSize], ExpandProp = new string[rankSize] }; var list1 = DbContext.Database.SqlQuery<ST_UkeyPersonMain>("select * from ST_UkeyPersonMain where PersonID >0"); var list = ( from t in ( from o in list1 select new { UnitName = o.DueDay}).ToList() orderby t.UnitName group t by new { UnitName = t.UnitName } into G select new { UnitName = G.FirstOrDefault().UnitName, Count = G.Count() } into x orderby x.Count descending select x).ToList(); int num = 0; if (list == null || 0 >= list.Count()) { ChartSeries<int> chartSeries = new ChartSeries<int>() { Data = new int[rankSize], Name = string.Concat("UK排行Top", rankSize.ToString()) }; ChartSeries<int> chartSeries1 = chartSeries; for (int i = 0; i < rankSize; i++) { chartSeries1.Data[num] = 0; int num1 = num; num = num1 + 1; lineChartDataModel.ExpandProp[num1] = ""; } lineChartDataModel.SeriesData.Add(chartSeries1); return lineChartDataModel; } ChartSeries<int> chartSeries2 = new ChartSeries<int>() { Data = new int[rankSize], Name = string.Concat("UK排行排行Top", rankSize.ToString()) }; ChartSeries<int> count = chartSeries2; foreach (var variable in list.Take(rankSize)) { count.Data[num] = (int)variable.Count; int num2 = num; num = num2 + 1; lineChartDataModel.ExpandProp[num2] = variable.UnitName.ToString(); lineChartDataModel.XAxisData[num2] = (num2 + 1).ToString(); } lineChartDataModel.SeriesData.Add(count); return lineChartDataModel; } }
解决方案
50
这个问题的重点并不是代码,是sql语句吧?
可以看到,x轴的设置
可以看到,x轴的设置
xAxis : [ { type : "category", data : ["1月","2月","3月","4月","5月","6月","7月","8月","9月","10月","11月","12月"] } ]
那么顾名思义,你的区间范围,应该是
xAxis : [ { type : "category", data : ["0-30",‘31-90’....] } ]
所以,你应该先通过sql查询出数据,数据格式可能如下
区间 , 值
0-30 , 140
30-90 , 155
…..
…..
然后赋值给前台的echart控件。这个都需要本人看api文档 http://echarts.baidu.com/demo.html#bar1
50
看你代码也有对取出来的结果做各种操作,那将echars的数据源处理成你的区分分割方式也不困难吧,不也就是个
source.Select(u=>{ if(u.xxx<=30) return 0; else if(u.xxx<=90) return1; //... else return n; }).GroupBy(n=>n);
这样不就分组了