asp.net中chart控件如何让X轴绑定两行数据源,比如下图,Y轴显示销售额,和成本。X轴显示分店和区域。 30

 我来答
游子归来2014
2015-06-23 · TA获得超过1109个赞
知道小有建树答主
回答量:176
采纳率:100%
帮助的人:98.8万
展开全部

你参考着一下对应修改一下就好,希望能帮助到你!

前台代码:
<asp:Chart ID="Chart1" runat="server" Height="400px" Width="500px">
            <Series>
                <asp:Series Name="Series1" ChartType="Column" ChartArea="ChartArea1">
                </asp:Series>
                <asp:Series Name="Series2" ChartType="Column" ChartArea="ChartArea1">
                </asp:Series>
            </Series>
            <ChartAreas>
                <asp:ChartArea Name="ChartArea1">
                </asp:ChartArea>
            </ChartAreas>
      </asp:Chart>

后台代码:

protected void Page_Load(object sender, EventArgs e)

        {

            DataTable dt = default(DataTable);

            dt = CreateDataTable();

 

            //设置图表的数据源

            Chart1.DataSource = dt;

 

            //设置图表Y轴对应项

            Chart1.Series[0].YValueMembers = "Volume1";

            Chart1.Series[1].YValueMembers = "Volume2";

 

            //设置图表X轴对应项

            Chart1.Series[0].XValueMember = "Date";

             

            //绑定数据

            Chart1.DataBind();

        }

        private DataTable CreateDataTable()

        {

            //Create a DataTable as the data source of the Chart control

            DataTable dt = new DataTable();

 

            //Add three columns to the DataTable

            dt.Columns.Add("Date");

            dt.Columns.Add("Volume1");

            dt.Columns.Add("Volume2");

 

            DataRow dr;

 

            //Add rows to the table which contains some random data for demonstration

            dr = dt.NewRow();

            dr["Date"] = "Jan";

            dr["Volume1"] = 3731;

            dr["Volume2"] = 4101;

            dt.Rows.Add(dr);

 

            dr = dt.NewRow();

            dr["Date"] = "Feb";

            dr["Volume1"] = 6024;

            dr["Volume2"] = 4324;

            dt.Rows.Add(dr);

 

            dr = dt.NewRow();

            dr["Date"] = "Mar";

            dr["Volume1"] = 4935;

            dr["Volume2"] = 2935;

            dt.Rows.Add(dr);

 

            dr = dt.NewRow();

            dr["Date"] = "Apr";

            dr["Volume1"] = 4466;

            dr["Volume2"] = 5644;

            dt.Rows.Add(dr);

 

            dr = dt.NewRow();

            dr["Date"] = "May";

            dr["Volume1"] = 5117;

            dr["Volume2"] = 5671;

            dt.Rows.Add(dr);

 

            dr = dt.NewRow();

            dr["Date"] = "Jun";

            dr["Volume1"] = 3546;

            dr["Volume2"] = 4646;

            dt.Rows.Add(dr);

 

            return dt;

        }

页面显示:

追问
答非所问了,我是问X轴如何绑定两行数据?比如你的代码X轴绑定了月份,如何再绑定一行季度?
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式