解决后, 这个问题编程用asp.net多系列的图表,我发现另一个多系列图表另一个问题:
我想显示月度销售报告,显示最后演变m
的批准和否决提案个月。 几个月,没有任何拒绝的提案,因此下面的查询(C#/ Oracle)的返回一些空的结果。
select to_char(c.date,'YYYYMM') ctb_month,
c.approved,
count(distinct c.f1) amt_c,
count(b.f1) amt_b,
sum(nvl(b.value,0)) sum_values
from bens b
join contracts c
on b.contract_id = c.f1
where b.seller = :USR_ID
AND c.date
BETWEEN add_months(:DATAI,:MONTHS) AND :DATAI
group by to_char(c.date,'YYYYMM'), c.approved
order by ctb_month
OBS:在绑定:MONTHS
参数,我要确保它的值是负的。
查询结果的实施例:
CTB_MONTH APPROVED AMT_C AMT_B SUM_VALUES
201209 APPROVED 10 20 1234.56
201209 PENDING 3 3 120.21
201210 APPROVED 12 18 850.52
201210 PENDING 4 4 158.71
201210 REJECTED 1 1 80.40
注:在这种情况下,有没有在201209当前卖方的任何拒绝的提议。
代码来填充图:
我存储在由较低层的变种传入的数据report
和过滤通过它的数据公司的APPROVED
状态:
var approved = queryResult
.Where(r => r.APPROVED == "APPROVED")
.ToList()
;
var rejected = queryResult
.Where(r => r.APPROVED == "REJECTED")
.ToList()
;
var pending = queryResult
.Where(r => r.APPROVED == "PENDING")
.ToList()
;
然后,我创建在一个循环系列
for (int i = 0; i < 6; i++) {
Series temp = new Series {
XAxisType = AxisType.Primary,
XValueType = ChartValueType.DateTime,
YAxisType = AxisType.Primary,
//mostra só a quantidade de contratos
IsValueShownAsLabel = i % 2 == 0 ? true : false,
ChartType = SeriesChartType.Column,
CustomProperties = "EmptyPointValue=Zero",
Legend = "Legenda"
};
grafico.Series.Add(temp);
}
和数据绑定每个系列手工
// approved contracts
grafico.Series[0].Points.DataBindXY(approved, "MONTH", approved, "AMT_C");
grafico.Series[0].LegendText = "Cont. approved";
// approved bens
grafico.Series[1].Points.DataBindXY(approved, "MONTH", approved, "AMT_B");
grafico.Series[1].LegendText = "Ben. approved";
grafico.Series[1].ChartType = SeriesChartType.Line;
// pending contracts
grafico.Series[2].Points.DataBindXY(pending, "MONTH", pending, "AMT_C");
grafico.Series[2].LegendText = "Cont. pending";
// pending bens
grafico.Series[3].Points.DataBindXY(pending, "MONTH", pending, "AMT_B");
grafico.Series[3].LegendText = "Ben. pending";
grafico.Series[3].ChartType = SeriesChartType.Line;
// rejected contracts
grafico.Series[4].Points.DataBindXY(rejected, "MONTH", rejected, "AMT_C");
grafico.Series[4].LegendText = "Cont. rejected";
// rejected bens
grafico.Series[5].Points.DataBindXY(rejected, "MONTH", rejected, "AMT_B");
grafico.Series[5].LegendText = "Ben. rejected";
grafico.Series[5].ChartType = SeriesChartType.Line;
注: grafico
是我的图表对象; 一些视觉设置在所定义<asp:Chart>
标记。
当我运行应用程序,完整的系列绘制正确,但不完整的系列片(201209 /拒绝,在上面的例子),在错误中得出X
坐标(为201210的值在201209列平局,在这种情况下, ),仿佛对照忽略X
中传递的值DataBindXY
方法和顺序拉伸的值。
是否有人知道如何解决这个问题? 提前致谢。
[解决]感谢@jbl,图表绘制,现在在正确的地方的价值观。
编码:
var allMonths = queryResult
.Select(x => x.MONTH)
.Distinct()
.OrderBy(mes => mes)
;
foreach (var mes in allMonths) {
bool hasData = rejected.Any(r => r.MONTH == mes);
if (hasData == false) {
rejected.Add(new MonthlyData() { MONTH = mes, APPROVED = "REJECTED" });
}
hasData = pending.Any(r => r.MONTH == mes);
if (hasData == false) {
pending.Add(new MonthlyData() { MONTH = mes, APPROVED = "PENDING" });
}
hasData = approved.Any(r => r.MONTH == mes);
if (hasData == false) {
approved.Add(new MonthlyData() { MONTH = mes, APPROVED = "APPROVED" });
}
}
approved = approved.OrderBy(v => v.MONTH).ToList();
pending = pending.OrderBy(v => v.MONTH).ToList();
rejected = rejected.OrderBy(v => v.MONTH).ToList();
grafico.ChartAreas[0].AxisX.Interval = 1;
grafico.ChartAreas[0].AxisX.IntervalType = DateTimeIntervalType.Months;
grafico.ChartAreas[0].AxisX.IntervalOffset = 1;
grafico.ChartAreas[0].AxisX.IntervalOffsetType = DateTimeIntervalType.Months;
注:MonthlyData是一个简单的类,输送值在查询结果中的每一行。