0

I am trying to add series to a chart to compare results from different measurements. these results are stored in the sql database.

I am able to show results on the chart but only one at a time with a below code.

 public partial class MainForm : Form
 {
 chartBench.Series["Sample1"].XValueMember = "Distnc";
 chartBench.Series["Sample1"].YValueMembers = "Apert";

 chartBench.Series["Sample2"].XValueMember = "Distnc";
 chartBench.Series["Sample2"].YValueMembers = "Apert";  
 }

private void cbSample1_SelectionChangeCommitted(object sender, EventArgs e)
    {
        using (LinqDataClassesDataContext dataContext = new 
                               LinqDataClassesDataContext())
        {
            var query = dataContext.MeasResults
                    .Where(m => m.MoldID == 
                    cbBench.SelectedValue.ToString() && m.MeasId == 
                    Int16.Parse(cbSample1.SelectedValue.ToString()))
                    .ToList();

            chartBench.DataSource = query;
            chartBench.DataBind();

        }
    } 

 private void cbSample2_SelectionChangeCommitted(object sender,EventArgs e)
    {
        using (LinqDataClassesDataContext dataContext = new 
                               LinqDataClassesDataContext())
        {

            var query = dataContext.MeasResults
                        .Where(m => m.MoldID == 
                        cbBench.SelectedValue.ToString() && m.MeasId == 
                        Int16.Parse(cbSample2.SelectedValue.ToString()))
                        .ToList();

            chartBench.DataSource = query;
            chartBench.DataBind();
        }
    }

Problem is when i select a second sample to show in chart, chart gets updated completely, i lose first series (first sample), only second sample is shown. How can i display these 2 selected samples on the chart at the same time?

Teo Laferla
  • 41
  • 1
  • 7
  • The question is somehow vague. I assume that it is not related to LINQ and you just need to bind two charts in just one event. don't' you? – Mahyar Mottaghi Zadeh Aug 27 '19 at 09:16
  • let me explain like this; a measurement result set is consist from around 35 elements, 35 result corresponding 35 different distance point. Distant values are shown on x-axle and measurement values are shown in y axle. i want to show 2 different set of these on the chart in order to see the comparison between them. Not two charts but 2 series in one chart. – Teo Laferla Aug 27 '19 at 09:24
  • Do not bind the Chart itself! This almost never makes sense. - Bind the Points of a Series. ! [Now](https://stackoverflow.com/questions/33588055/drawing-a-chart-from-a-datatable/33588458#33588458) the issue is gone :-) – TaW Aug 27 '19 at 17:43
  • @TaW thank you. I've seen from your post that fourth element in the databind() method should be null. i didn't know that. – Teo Laferla Aug 28 '19 at 07:23
  • For this overload the last parameter is a list of extra fields that contain data for some extra properties.. Keep it "" if you don't need them. [Here](https://stackoverflow.com/questions/46212740/how-to-display-tooltips-with-various-data-in-ms-charts/46214021#46214021) is a discussion of how to use it.. – TaW Aug 28 '19 at 09:31

0 Answers0