0

我想向使用该Chart组件的用户展示一些精简的数据。

SQL(C#/甲骨文):

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

我在将 DataSet 传递给 .aspx 页面中的 ObjectDataSource 的方法中有此 SQL(该approved字段可以有 3 个值:REJECTED、APPROVED 和 PENDING)。

.aspx 页面中的图表:

<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 个条形图),但图表仅显示两列。 柱形图

4

2 回答 2

0

通过创建一个对象relatorio来保存返回的数据(而不是 DataSet)、使用 LINQ to Objects 过滤结果以及在 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;

在循环中创建系列

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");

数据绑定系列

// 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;
于 2012-10-11T12:47:55.617 回答
-1

为每个系列创建一个组..

例子: chart1.series[0]["StackedGroupName"] = "group1";

于 2014-12-29T19:39:10.453 回答