2

I'm trying to make chart with C#/mysql which has more than two series.

original database architecture is as follows

Ticker Date Field Value
1      2001  AA   23445
1      2002  AA   34523
1      2001  BB   63456
1      2002  BB   76345

Ticker is company code AA means total asset, BB means total equity

I searched quite a lot in google, however, cannot find way to do it

last try is this.

            MySqlConnection conn = new MySqlConnection(connString);
        MySqlCommand cmdDataBaseKK = new MySqlCommand(" Select Date, Value as 'ValueK' from htdbmain.mainfsdb where field = 'KK' and ticker = '" + FinalTicker + "'", conn);
        MySqlCommand cmdDataBaseJJ = new MySqlCommand(" Select Date, Value as 'ValueJ' from htdbmain.mainfsdb where field = 'AA' and ticker = '" + FinalTicker + "'", conn);

        try
        {
            MySqlDataAdapter sdaK = new MySqlDataAdapter();
            sdaK.SelectCommand = cmdDataBaseKK;
            DataTable dbdatasetK = new DataTable();
            sdaK.Fill(dbdatasetK);
            BindingSource KSource = new BindingSource();

            KSource.DataSource = dbdatasetK;
            dataGridView1.DataSource = KSource;
            sdaK.Update(dbdatasetK);

            chart1.DataSource = KSource;
            chart1.Series["Total Asset"].XValueMember = "Date";
            chart1.Series["Total Asset"].YValueMembers = "ValueK";
            chart1.DataBind();

            MySqlDataAdapter sdaJ = new MySqlDataAdapter();
            sdaJ.SelectCommand = cmdDataBaseJJ;
            DataTable dbdatasetJ = new DataTable();
            sdaJ.Fill(dbdatasetJ);
            BindingSource JSource = new BindingSource();

            JSource.DataSource = dbdatasetJ;
            dataGridView1.DataSource = JSource;
            sdaJ.Update(dbdatasetJ);

            chart1.DataSource = JSource;
            chart1.Series["Total Equity"].XValueMember = "Date";
            chart1.Series["Total Equity"].YValueMembers = "ValueJ";
            chart1.DataBind();

but I knew that chart only can have one datasource. I think, JOIN two database in one database source is one way but really don't know how to do it.(actually I spent almost 3 days in google :-), but only found join table in mysql)

Simon MᶜKenzie
  • 8,344
  • 13
  • 50
  • 77
Hong
  • 21
  • 2
  • Am I reading your SQL commands correct;y, as I see them as 2 calls to the same table. Can you put up the actual DDL for the table(s) and a grid view of the data would make this a lot easier to interpret – Mad Myche Apr 28 '17 at 01:42
  • Would this not be enough? `MySqlCommand cmdDataBase = new MySqlCommand(" Select Date, Value as 'Value' from htdbmain.mainfsdb where (field = 'AA' or field = 'KK') and ticker = '" + FinalTicker + "'", conn);` – Gusman Apr 28 '17 at 01:47
  • Looks like you need a multi-series chart, assuming you are using wpf, on top of @Gusman suggestion, also take a look at [this](http://stackoverflow.com/questions/5002786/multiple-series-charts-with-wpftoolkit) – spinalfrontier Apr 28 '17 at 02:05
  • to Gusman thanks for comment, however, when I follow your advise, it only shows one series. such as 2001 has two value data. (I need to separate it into two columns) – Hong Apr 28 '17 at 05:45

0 Answers0