Charting: How to preserve previous series while creating new series ?

  • Thread starter Thread starter Monostable
  • Start date Start date
M

Monostable

Guest
Hi,

I'm trying this code to plot multiple graphs on the same chartarea.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Windows.Forms.DataVisualization.Charting;

namespace ListTest
{
public partial class Form1 : Form
{
List<rdgPair> testRdgs = new List<rdgPair>();
testData AllTestsDta = new testData();

int curSeries=-1;

public Form1()
{
InitializeComponent();

chart1.Series.Clear();
}

private void button1_Click(object sender, EventArgs e)
{
Series newSeries = new Series("TEST " + curSeries)
{
ChartType = SeriesChartType.Line,
BorderWidth = 2
};

chart1.Series.Add(newSeries);
curSeries++;

rdgList tstRdgList = new rdgList();

for (int i = 0; i < 50; i++)
{
rdgPair rdgs = new rdgPair();
rdgs.elongRdg = curSeries * 100 + i * 100; //fake values.
rdgs.loadRdg = curSeries * 200 + i * 1000;
tstRdgList.Add(rdgs);
}

AllTestsDta.Add(tstRdgList);

chart1.DataSource = AllTestsDta[curSeries];

chart1.Series[curSeries].XValueMember = "elongRdg";
chart1.Series[curSeries].YValueMembers = "loadRdg";
chart1.DataBind();
}
}
//==========================================
public class rdgPair
{
public float loadRdg { get; set; }
public float elongRdg { get; set; }
}
//===========================================
public class rdgList : List<rdgPair> { }
//===========================================
public class testData : List<rdgList> { }


}


I find that when I create a new series, the previous plotted series disappears.

I know this does not happen while manually adding or binding to a simple list, and there is a mistake I'm making somewhere.

I need to preserve all the series' (plots/graphs) until I do a Series.Clear() ;

Please help me find the error. Thank you!

Continue reading...
 
Back
Top