textbox and chart?

Posted on 2006-05-26
Last Modified: 2010-04-16
im a 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

Question by:paulwhelan
    LVL 44

    Accepted Solution

    Hi paulwhelan,

    you could start with a sample like

    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

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

    share what you know, learn what you don't

    Expert Comment

    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?


    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)


    Expert Comment

    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);

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Join & Write a Comment

    Introduction                                                 Was the var keyword really only brought out to shorten your syntax? Or have the VB language guys got their way in C#? What type of variable is it? All will be revealed.   Also called…
    Article by: Najam
    Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
    Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
    This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor ( If you're looking for how to monitor bandwidth using netflow or packet s…

    731 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now