MSChart的添加从数据库的多系列 [英] MsChart Add Multiple Series from Database

查看:384
本文介绍了MSChart的添加从数据库的多系列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想当时我的图表添加不同的折线图之一。所以我有一个按钮,一个文本框。我输入code和负载从我的数据库中的系列。问题是,新的生产线系列覆盖旧线系列。所以我决定继续增加一系列的道成一个gridview,我遍历它,填满图表;同样的结果。

I want to add different line chart one at the time to my chart. So i have a textbox with a button . i input a code and load the series from my database. The problem is that the new line series override the old line series. so i decided to keep tract of the added series into a gridview, i loop through it and fill the chart; same result.

这是我的code

void AddSerie(string stockName)
    {
        try
        {

            Legend legend = new Legend(stockName);
            Chart1.Legends.Add(legend);
            Series series = new Series(stockName);
            Chart1.Series.Add(series);

             string[] _data = new string[3];
            _data[0] = stockName;
            _data[1] = "2010-01-01";
            _data[2] = "2015-03-15";

            DataSet ds = DBSelect(_data, "web_price_series");

            Chart1.DataSource = ds;
            Chart1.Series[stockName].XValueMember = "tdate";
            Chart1.Series[stockName].YValueMembers = "value";
            Chart1.Series[stockName].ChartType = SeriesChartType.Line;
            Chart1.DataBind();

        }
        catch (Exception)
        {
            throw;
        }
    }

这是我如何调用该方法

foreach (GridViewRow row in GridView1.Rows)
        {
            if (row.RowType == DataControlRowType.DataRow)
            {
                AddSerie(row.Cells[0].Text);
            }
        }

和我有展示两个系列的传说,但图表显示只有一行。

and i have the legend showing two series but the chart displays only one line.

我添加了此图片显示在图表的使用MarkerStyle两家公司的第二输出。

i added this picture to show the second output of the chart for two companies using MarkerStyle.

这是我所想要实现的例子。

This is an example of what i want to achieve .

这是表中的结构

任何帮助吗?

推荐答案

而不是使用我用另一种方法的数据绑定的:
Chart1.Series [0] .Points.AddXY(XValues​​,Yalues​​);

Instead of using the databind i used another method: Chart1.Series[0].Points.AddXY(XValues, Yalues);

void AddSerie(string stockName)
{
    try
    {

        Legend legend = new Legend(stockName);
        Chart1.Legends.Add(legend);
        Series series = new Series(stockName);
        Chart1.Series.Add(series);

         string[] _data = new string[3];
        _data[0] = stockName;
        _data[1] = "2010-01-01";
        _data[2] = "2015-03-15";

        DataSet ds = DBSelect(_data, "web_price_series");

        Chart1.DataSource = ds;
        Chart1.Series[stockName].XValueMember = "tdate";
        Chart1.Series[stockName].YValueMembers = "value";
        Chart1.Series[stockName].ChartType = SeriesChartType.Line;

        foreach (DataRow row in ds.Tables[0].Rows)
        {
           Chart1.Series[stockName].Points.AddXY(row[0], row[1]);
        }

       // Chart1.DataBind();

    }
    catch (Exception)
    {
        throw;
    }
}

这篇关于MSChart的添加从数据库的多系列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆