Click here to Skip to main content
15,891,704 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi Need Namespaces for SeriesCollection And points in chart are not found in my code

What I have tried:

C#
<pre>using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Drawing;
using System.Drawing.Drawing2D;

namespace dotnetpro
{
    public partial class sample1 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            Chart.TitleBox.Label.Text = "Student Progress";
            Chart.Width = 750;
            Chart.Height = 550;
            SeriesCollection mySC = Calculate();
            Chart.XAxis.Label.Text = "Marks";
            Chart.YAxis.Label.Text = "No of Students";
            Chart.SeriesCollection.Add(Calculate());
            Chart.DefaultSeries.DefaultElement.URL = "JavaScript: myAlert(\'Clicked on element %Name in series %SeriesName \')";
            Chart.TitleBox.Position = TitleBoxPosition.Full;
            Chart.TitleBox.Label.Font = new Font("TimesRoman", 10, FontStyle.Bold | FontStyle.Italic);
            Chart.TitleBox.Label.Alignment = StringAlignment.Center;
            Chart.TitleBox.Label.Color = Color.DarkBlue;
            Chart.TitleBox.Background.Color = Color.FromArgb(225, 122, 212);
            Chart.TitleBox.Padding = 7;
            Chart.LegendBox.DefaultEntry.LabelStyle.Font = new Font("Arial", 10, FontStyle.Italic);
            Chart.LegendBox.Line.Color = Color.FromArgb(56, 66, 177);
            Chart.LegendBox.Line.Width = 2;
            Chart.LegendBox.Background = new Background(Color.FromArgb(165, 174, 255), Color.FromArgb(233, 235, 240), 45);
            Chart.LegendBox.Orientation = dotnetCHARTING.Orientation.Bottom;
        }
       SeriesCollection Calculate()
        {
            SeriesCollection SC = new SeriesCollection();
            Random myR = new Random(1);
            for (int a = 0; a < 4; a++)
            {
                Series s = new Series();
                s.Name = "Series " + a.ToString();
                for (int b = 0; b < 1; b++)
                {
                    Element e = new Element();
                    e.Name = "Element " + b.ToString();
                    e.YValue = myR.Next(50);
                    s.Elements.Add(e);
                }

                SC.Add(s);
            }
            SC[0].Element.Color = Color.FromArgb(49, 255, 49);
            SC[0].Elements[0].Name = "English";
            SC[0].LegendEntry.Value = "13";
            SC[0].LegendEntry.Name = "Between 10-15";

            SC[1].Element.Color = Color.FromArgb(255, 255, 0);
            SC[1].Elements[0].Name = "Maths";
            SC[1].LegendEntry.Value = "32";
            SC[1].LegendEntry.Name = "Between 10-40";

            SC[2].Element.Color = Color.FromArgb(255, 99, 49);
            SC[2].Elements[0].Name = "Science";
            SC[2].LegendEntry.Value = "6";
            SC[2].LegendEntry.Name = "Between 0-10";

            SC[3].Element.Color = Color.FromArgb(0, 156, 255);
            SC[3].Elements[0].Name = "Computer";
            SC[3].LegendEntry.Value = "18";
            SC[3].LegendEntry.Name = "Between 15-30";
            return SC;
        }


    }
}
Posted
Updated 2-Mar-17 18:29pm

1 solution

Sounds like you are missing a namespace reference. Here: SeriesCollection Class (System.Windows.Forms.DataVisualization.Charting)[^]

A quick tip for resolving namespaces (and other neat stuff):

In VS2015 (and VS2013?), put the cursor anywhere in the line with the squiggly red line, using shortcut CTRL+. (CTRL key + '.' (Dot) key) or right-click and select "Quick Actions and Refactorings...", if the correct DLL is linked in, the IntelliSense should give you the ability to quickly add the correct Using {namespace}; reference.
 
Share this answer
 
Comments
Karthik_Mahalingam 3-Mar-17 7:39am    
5 for the tip :)
Member 12605293 3-Mar-17 7:46am    
:P
Graeme_Grant 3-Mar-17 7:55am    
Thanks... I love my keyboard shortcuts. :)
Karthik_Mahalingam 3-Mar-17 12:51pm    
:)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900