Nandomo -3 Junior Poster

I have a webservice that draws a line chart, first line: an range of dates and their stock values. Second line: a moving average of the dates, so if I input a value of 5 it will give me the same data as line 1 but with 5 day intervals. I want to figure out how to replace the second line without clearing the first. This is what I've done, unsuccessfully.

localhost.ServiceClient client = new localhost.ServiceClient();

            localhost.GraphData[] graph2 = client.CalcMovingAverages(DateTime.Parse(textBox1.Text), DateTime.Parse(textBox2.Text), Int32.Parse(textBox3.Text));


            Series S2 = new Series("Series 2");
            S2.Color = Color.Navy;
            S2.XValueMember = "Date";
            S2.YValueMembers = "Value";
            S2.BorderWidth = 2;                              // line thickness
            S2.BorderDashStyle = ChartDashStyle.Solid;        // line style
            S2.IsVisibleInLegend = false;
            // Experiment with different types of charts
            S2.ChartType = SeriesChartType.Line;
            //S.ChartType = SeriesChartType.Bar;
            S2.XValueType = ChartValueType.Date;
            S2.YValueType = ChartValueType.Double;

            if (MyChart.Series.IndexOf("Series 2") != -1)
            {
                MyChart.Series["Series 2"].Points.Clear();

                foreach (localhost.GraphData data in graph2)
                {
                    S2.Points.AddXY(data.Date, data.Value);
                }

            }
            else
            {
                MyChart.Series.Add(S2);

                // A Series object contains DataPoint objects. The AddXY method adds a new DataPoint
                // to the Points collection (a DataPointCollection object).
                foreach (localhost.GraphData data in graph2)
                {
                    S2.Points.AddXY(data.Date, data.Value);
                }
            }
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.