Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Drawing;
- using System.Drawing.Drawing2D;
- namespace DrawLib_test
- {
- class BarChart
- {
- float[] values;
- Pen pen;
- int h, distance;
- float width, height;
- public BarChart(params int[] values)
- {
- this.values = new float[values.Length];
- for (int i = 0; i < values.Length; i++)
- {
- this.values[i] = (float)values[i];
- }
- }
- public void DrawChart(Graphics g, Rectangle area)
- {
- h = area.Width;
- distance = 25;
- height = ((area.Height / values.Length - 1) - distance) < 50 ?
- ((area.Height / values.Length - 1) - distance) : 50;
- pen = new Pen(Color.Red);
- float max = values.Max();
- for (int i = 0; i < values.Length; i++)
- {
- float sum = values.Sum();
- width = (values[i] / sum) * (h / max);
- Rectangle rect = new Rectangle(20, distance, (int)width, (int)height);
- distance += (int)height + 10;
- g.FillRectangle(pen.Brush, rect);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement