Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


textbox and chart?

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

Question by:paulwhelan
  • 2
LVL 44

Accepted Solution

bruintje earned 200 total points
ID: 16769135
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

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

ID: 16788194
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

ID: 16788437
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

[Webinar] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…

581 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