Click here to Skip to main content
15,938,122 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I want to create chart by commands to put it in loop later, but it failed!

I tried this:

Chart Chr = new Chart();
	Chr.ID = "chr1";

        Chr.Series.Add("Age");
        Chr.Series["Age"].Points.AddXY("Max", 33);
        Chr.Series["Age"].Points.AddXY("Xam", 50);
        Chr.Series["Age"].Points.AddXY("Nax", 20);
        Chr.Series["Age"].Points.AddXY("Xan", 80);
		
        Chr.Width = 500;

        Panel1.Controls.Add(Chr);




It's run.. but it shows nothing!
It take space on the page, but blank space..

Aftar that, I made these changes:





Chart Chr = new Chart();

        Chr = new Chart();

        Chr.ID = "chr2";
        Chr.ImageLocation = "ChartPic_#SEQ(300,3)";

        Chr.Series.Add("Ageq");

        Chr.Series["Ageq"].ChartType = SeriesChartType.Pie;
        Chr.Series["Ageq"].Palette = ChartColorPalette.Berry;

        Chr.Series["Ageq"].BackImage = "ChartPic_#SEQ(300,3)";
      
        Chr.Series["Ageq"].Points.AddXY("Maxq", 11);
        Chr.Series["Ageq"].Points.AddXY("Xamq", 22);
        Chr.Series["Ageq"].Points.AddXY("Naxq", 55);
        Chr.Series["Ageq"].Points.AddXY("Xanq", 44);

        Chr.Width = 600;

        Chr.Height = 100;

        Chr.Palette = ChartColorPalette.Berry;

        Chr.Visible = true;
      
        Panel1.Controls.Add(Chr);



It gave me the same result..
It's run.. but it shows nothing!
Posted
Updated 16-Aug-14 12:25pm

You are missing Series.ChartArea Property and Legend Property

Here i have done some modifications to your code

C#
ChartArea chartArea1 = new ChartArea();
           Legend legend1 = new Legend();

           Series series1 = new Series();

           Chart Chr = new Chart();

           Chr = new Chart();

           Chr.Name = "chr2";

           Chr.ChartAreas.Add(chartArea1);
           legend1.Name = "Legend1";
           Chr.Legends.Add(legend1);

           Chr.Series.Add("Ageq");

           Chr.Series["Ageq"].ChartType = SeriesChartType.Pie;
           Chr.Series["Ageq"].Palette = ChartColorPalette.Berry;

           Chr.Series["Ageq"].Points.AddXY("Maxq", 11);
           Chr.Series["Ageq"].Points.AddXY("Xamq", 22);
           Chr.Series["Ageq"].Points.AddXY("Naxq", 55);
           Chr.Series["Ageq"].Points.AddXY("Xanq", 44);

           Chr.Size = new System.Drawing.Size(559, 418);

           Chr.Palette = ChartColorPalette.Berry;

           Chr.Visible = true;

           panel1.Controls.Add(Chr);
 
Share this answer
 
That's right!
Thank you it worked..

I've done 3 little changes on the code to run on the right way..

        ChartArea chartArea1 = new ChartArea();
        Legend legend1 = new Legend();

        Series series1 = new Series();

        Chart Chr = new Chart();

        Chr = new Chart();

Chr.ID = "chr2";

        Chr.ChartAreas.Add(chartArea1);
        legend1.Name = "Legend1";
        Chr.Legends.Add(legend1);

        Chr.Series.Add("Ageq");

        Chr.Series["Ageq"].ChartType = SeriesChartType.Pie;
        Chr.Series["Ageq"].Palette = ChartColorPalette.Berry;

        Chr.Series["Ageq"].Points.AddXY("Maxq", 11);
        Chr.Series["Ageq"].Points.AddXY("Xamq", 22);
        Chr.Series["Ageq"].Points.AddXY("Naxq", 55);
        Chr.Series["Ageq"].Points.AddXY("Xanq", 44);

Chr.Width = 500;
           
        Chr.Palette = ChartColorPalette.Berry;

        Chr.Visible = true;

Panel1.Controls.Add(Chr);


Thank you again..
 
Share this answer
 

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



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