C# 如何在asp.net中显示多系列柱状图

C# 如何在asp.net中显示多系列柱状图,c#,asp.net,.net,data-visualization,mschart,C#,Asp.net,.net,Data Visualization,Mschart,在我的web应用程序中,我需要显示从数据表绑定的柱状图数据。我在图表区域的X轴上有3列。我需要显示col1一侧和col1第2列。我还需要显示数据表中的系列显示图例的不同颜色 我需要像这样的我怎么能做到这一点请任何人都可以帮助我如何做到这一点 谢谢假设您的数据表具有以下列/类型: Columns.Add("Month", typeof(DateTime)); Columns.Add("Charges", typeof(double)); Columns.Add("Payme

在我的web应用程序中,我需要显示从数据表绑定的柱状图数据。我在图表区域的X轴上有3列。我需要显示col1一侧和col1第2列。我还需要显示数据表中的系列显示图例的不同颜色

我需要像这样的我怎么能做到这一点请任何人都可以帮助我如何做到这一点


谢谢

假设您的
数据表
具有以下列/类型:

    Columns.Add("Month", typeof(DateTime));
    Columns.Add("Charges", typeof(double));
    Columns.Add("Payments", typeof(double));
ASPX:

    <asp:Chart ID="Chart1" runat="server" Height="400px" Width="600px">
        <ChartAreas>
            <asp:ChartArea Name="ChartArea1">
                <AxisY>
                    <MajorGrid LineColor="DarkGray" LineDashStyle="Dot" />
                    <LabelStyle Format="C2" />
                </AxisY>
                <AxisX>
                    <MajorGrid LineColor="DarkGray" LineDashStyle="Dot" />
                </AxisX>
            </asp:ChartArea>
        </ChartAreas>
        <Legends>
            <asp:Legend Name="Legend1">
            </asp:Legend>
        </Legends>
    </asp:Chart>
    protected void Page_Load(object sender, EventArgs e)
    {
        foreach (DataRow r in dt.Rows)
        {
            Series s = new Series(string.Format("{0} {1}", ((DateTime)r["Month"]).ToString("MMM"), ((DateTime)r["Month"]).Year));
            s.ChartType = SeriesChartType.Column;
            s.Points.AddXY("Charges", new object[] { r["Charges"] });
            s.Points.AddXY("Payments", new object[] { r["Payments"] });

            Chart1.Series.Add(s);
        }
    }


编辑:假设您的
DataTable
具有以下列/类型:

    Columns.Add("Month", typeof(string));
    Columns.Add("Charges", typeof(double));
    Columns.Add("Payments", typeof(double));

然后,您应该将代码更改为:

    protected void Page_Load(object sender, EventArgs e)
    {
        foreach (DataRow r in dt.Rows)
        {
            Series s = new Series((string)r["Month"]);
            s.ChartType = SeriesChartType.Column;
            s.Points.AddXY("Charges", new object[] { r["Charges"] });
            s.Points.AddXY("Payments", new object[] { r["Payments"] });

            Chart1.Series.Add(s);
        }
    }

您的表中有哪些列类型?在我的数据表中,我已经有了
Month
列和类似于此的值
2016年8月
如何将其纳入序列您表中每个列的类型是什么?
Month
列的类型是什么?
付款
列的类型是什么?
费用
列的类型是什么?当我为
月份
值取列时
08/01/2016 00:00:00
在我更改后,它将是这样的
2016年8月
,列
费用
205711.7900
将更改为
卢比值
付款
值也与此相同。请告诉我怎么做我搜索了很多我没有得到我编辑了我的答案,请看看这是否适合你。
    protected void Page_Load(object sender, EventArgs e)
    {
        foreach (DataRow r in dt.Rows)
        {
            Series s = new Series((string)r["Month"]);
            s.ChartType = SeriesChartType.Column;
            s.Points.AddXY("Charges", new object[] { r["Charges"] });
            s.Points.AddXY("Payments", new object[] { r["Payments"] });

            Chart1.Series.Add(s);
        }
    }