如何显示2个参数分组asp.net图 [英] How to show asp.net chart grouped by 2 parameters
问题描述
我想present使用图
成分浓缩的一些数据给用户。
I want to present some condensed data to the user using the Chart
component.
SQL(C#/ Oracle)的:
SQL (C# / Oracle):
SELECT c.date, c.approved, count(distinct c.f1) amt_c, count(b.f1) amt_b, sum(b.value) sum_values
FROM contracts c
JOIN bens b ON c.ben_id = b.id
WHERE :YearMonth = to_char(c.date,'YYYYMM') AND NOT c.approved = 'REJECTED'
GROUP BY c.date, c.approved
ORDER BY c.date
我有这个SQL在传递一个DataSet到ObjectDataSource在.aspx页面的方法(即批准
字段可以有3个值:拒绝批准和正在申请的)
I have this SQL in a method that passes a DataSet to the ObjectDataSource in the .aspx page (The approved
field can have 3 values: REJECTED, APPROVED and PENDING).
图表中的.aspx页面:
Chart in .aspx page:
<asp:Chart ID="Chart1" runat="server" DataSourceID="RelatorioDataSource"
Width="700px" Compression="10" Palette="Chocolate">
<Series>
<asp:Series Name="Contracts" XValueMember="date"
YValueMembers="amt_c" IsXValueIndexed="False"
XValueType="DateTime" IsValueShownAsLabel="True" BorderDashStyle="DashDot"
CustomProperties="DrawingStyle=Emboss, EmptyPointValue=Zero, DrawSideBySide=True"
YValuesPerPoint="4">
</asp:Series>
<asp:Series BorderDashStyle="DashDot" ChartArea="ChartArea1"
CustomProperties="DrawingStyle=Emboss, EmptyPointValue=Zero, DrawSideBySide=True"
IsValueShownAsLabel="True" Name="Bens"
XValueMember="date" XValueType="DateTime"
YValueMembers="amt_b" YValuesPerPoint="4">
</asp:Series>
</Series>
<ChartAreas>
<asp:ChartArea Name="ChartArea1">
</asp:ChartArea>
</ChartAreas>
</asp:Chart>
我想告诉每一天(4条)批准/待定的合同/ BENS的数字,但图表显示只有两列。
I want to show the numbers of approved/pending contracts/bens for each day (4 bars), but the chart shows only two columns.
推荐答案
通过创建一个对象 relatorio
持有(而不是数据集)返回的数据,过滤解决使用结果的LINQ to对象,并以编程方式添加系列codeBehind。
Solved by creating an object relatorio
to hold the returned data (instead of the DataSet), filtering the results using LINQ to Objects, and adding the series programmatically in codeBehind.
var approved = relatorio
.Where(r => r.APPROVED == "APPROVED")
.ToList()
;
var pending = relatorio
.Where(r => r.APPROVED == "PENDING")
.ToList()
;
创建传说
Legend legenda = new Legend("Legenda");
legenda.Docking = Docking.Bottom;
legenda.LegendStyle = LegendStyle.Row;
legenda.Alignment = System.Drawing.StringAlignment.Center;
在一个循环中创建一系列
Creating series in a loop
for (int i = 0; i < 4; 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);
}
approvedValues.Points.DataBindXY(approved, "DATE", approved, "SUM_VALUES");
数据绑定系列
DataBinding series
// approved CONTRACTS
grafico.Series[0].Points.DataBindXY(approved, "DATE", approved, "AMT_C");
grafico.Series[0].LegendText = "Contratos approved";
// approved BENS
grafico.Series[1].Points.DataBindXY(approved, "DATE", approved, "AMT_B");
grafico.Series[1].LegendText = "Ben approved";
grafico.Series[1].ChartType = SeriesChartType.Line;
// pending CONTRACTS
grafico.Series[2].Points.DataBindXY(pending, "DATE", pending, "AMT_C");
grafico.Series[2].LegendText = "Contratos pending";
// pending BENS
grafico.Series[3].Points.DataBindXY(pending, "DATE", pending, "AMT_B");
grafico.Series[3].LegendText = "Ben pending";
grafico.Series[3].ChartType = SeriesChartType.Line;
这篇关于如何显示2个参数分组asp.net图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!