2

目前,我只能为 1 个未付费系列生成图表类型列。

在 mySQL 中,我的列名状态始终是这三个值中的任何一个未付费/付费/完成。

如何计算每种状态(未付费/已付费/完成)的客户数量并将其添加到图表中?

默认.aspx

    <asp:Chart ID="Chart1" runat="server" Palette="EarthTones">
            <Legends>
            <asp:Legend Alignment="Center" Docking="Bottom" IsTextAutoFit="False" Name="Default" LegendStyle="Row" />
            </Legends>
            <series>
                <asp:Series Name="Unpaid" XValueMember="MONTH(paymentDate)" YValueMembers="COUNT(status)"  ShadowColor="#FF9900"></asp:Series>
            </series>
            <chartareas>
                <asp:ChartArea Name="ChartArea1">
                </asp:ChartArea>
            </chartareas>
        </asp:Chart>

默认.aspx.cs

    protected void displayGraph()
{
    string Up = "Unpaid";
    string month = DateTime.Now.ToString("MMMM");

    MySqlConnection con = new MySqlConnection("server=localhost;userid=root;password=;database=obsystem");
    con.Open();
    MySqlCommand cmd = new MySqlCommand("SELECT COUNT(status),MONTH(paymentDate) FROM monthlytracker WHERE status='" + Up + "'", con);

    MySqlDataAdapter da = new MySqlDataAdapter(cmd);

    DataTable dt = new DataTable(); 


    da.Fill(dt);

    Chart1.DataSource = dt;
    Chart1.ChartAreas["ChartArea1"].AxisX.Title = "Payment Status";
    Chart1.ChartAreas["ChartArea1"].AxisY.Title = "Amount";
    Chart1.DataBind(); 
}

有人可以帮帮我吗?

提前谢谢你。非常感谢您的帮助。

4

1 回答 1

1

替换COUNTSUM,如下所示:

SELECT
    SUM(CASE WHEN status='unpaid' THEN 1 ELSE 0 END) as Unpaid
,   SUM(CASE WHEN status='paid' THEN 1 ELSE 0 END) as Paid
,   SUM(CASE WHEN status='finished' THEN 1 ELSE 0 END) as Finished
FROM monthlytracker
WHERE ... -- the filter condition

这将为每个付款状态生成三列计数。

于 2013-08-17T10:45:17.527 回答