Link to home
Start Free TrialLog in
Avatar of paulwhelan
paulwhelan

asked on

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
ASKER CERTIFIED SOLUTION
Avatar of Brian Mulder
Brian Mulder
Flag of Netherlands image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of amoran
amoran

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


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