textbox and chart?

hi
im a c#.net newbie.
i started a web application and wondered if its possible
to have a textbox where you could only enter 1-100 and then it would show a pie chart (or bar chart or something similar) with the selected data.

i.e. if you enter 17 the pie chart shows 17 and 83

Thanks
Paul
paulwhelanAsked:
Who is Participating?
 
bruintjeCommented:
Hi paulwhelan,
----------

you could start with a sample like
source: http://www.codeguru.com/csharp/csharp/cs_graphics/chartsandgraphing/article.php/c6145/

it includes the simple steps of creating a pie chart and a webppage to draw and show your chart based on this part of the routine

for( int i = 0; i < vals.Length; i++ )
    {
      current += vals[i];
      start = end;
      end = (float) (current / total) * 360.0f;
      graphics.FillPie(brushes[i % 10], 0.0f, 0.0f, width,
                       height, start, end - start);
    }

which cuts the pie into 10 parts

a more complex sample is this one
http://www.c-sharpcorner.com/UploadFile/desaijm/ExplodedPieChart10172005025429AM/ExplodedPieChart.aspx?ArticleID=c057415c-25ae-4f84-bb5b-137f276868c5

which comes with a sample page if you click the run this sample button you'll see something that you could use

----------
bruintje
share what you know, learn what you don't
0
 
amoranCommented:
Hi bruintje,

I was able to get the commented code below to work - it draws a rectangle.

But I couldn't seem to see a pie chart when I did the rest?

Thanks
Paul

private void Form1_Paint(object sender, PaintEventArgs pe)
        {
            //Graphics g = pe.Graphics;
            //Pen pn = new Pen(Color.Blue, 100);
            //Rectangle rect = new Rectangle(50, 50, 200, 100);
            //g.DrawEllipse(pn, rect);

            Bitmap bitmap = new Bitmap(10, 10, PixelFormat.Format32bppArgb);
            Graphics graphics = Graphics.FromImage(bitmap);

            SolidBrush[] brushes = new SolidBrush[2];
            brushes[0] = new SolidBrush(Color.Yellow);
            brushes[1] = new SolidBrush(Color.Green);

            decimal[] vals = { 20, 80 };
            // Sum the inputs to get the total
            decimal total = 0.0m;
            foreach (decimal val in vals)
                total += val;

            // Draw the pie chart
            float start = 0.0f;
            float end = 0.0f;
            decimal current = 0.0m;
            for (int i = 0; i < vals.Length; i++)
            {
                current += vals[i];
                start = end;
                end = (float)(current / total) * 360.0f;
                graphics.FillPie(brushes[i % 10], 0.0f, 0.0f, 10, 10, start, end - start);
            }

            // Clean up the brush resources
            foreach (SolidBrush cleanBrush in brushes)
                cleanBrush.Dispose();


        }
0
 
amoranCommented:
Actually I got this to work


Graphics g = pe.Graphics;

            Pen penpiegreen = new Pen(Color.Green, 2);
            Pen penpiered = new Pen(Color.Red, 2);
            Brush brushpiegreen = new SolidBrush(System.Drawing.Color.Green);
            Brush brushpiered = new SolidBrush(System.Drawing.Color.Red);
           
            g.SmoothingMode = SmoothingMode.AntiAlias;
           
            g.DrawPie(penpiegreen, 20, 250, 125, 125, 180, 340);
            g.DrawPie(penpiered, 20, 250, 125, 125, 160, 20);
            g.FillPie(brushpiegreen, 20, 250, 125, 125, 180, 340);
            g.FillPie(brushpiered, 20, 250, 125, 125, 160, 20);
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.