Skip to content

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

2 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 

Repository files navigation

using System; using System.Drawing; using System.Windows.Forms;

public class BarGraphForm : Form { private int[] values = { 10, 25, 15, 40, 30 };

public BarGraphForm()
{
    this.Text = "Bar Graph Example";
    this.Size = new Size(600, 400);
    this.Paint += new PaintEventHandler(DrawBarGraph);
}

private void DrawBarGraph(object sender, PaintEventArgs e)
{
    Graphics g = e.Graphics;
    Brush barBrush = Brushes.Blue;

    int barWidth = 50;
    int spacing = 20;
    int x = 50;
    int maxHeight = 200;

    int maxValue = 0;
    foreach (int val in values)
    {
        if (val > maxValue) maxValue = val;
    }

    for (int i = 0; i < values.Length; i++)
    {
        int barHeight = (int)((values[i] / (float)maxValue) * maxHeight);
        int y = 300 - barHeight;

        g.FillRectangle(barBrush, x, y, barWidth, barHeight);
        g.DrawString(values[i].ToString(), this.Font, Brushes.Black, x, y - 20);

        x += barWidth + spacing;
    }
}

[STAThread]
public static void Main()
{
    Application.EnableVisualStyles();
    Application.Run(new BarGraphForm());
}

}

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors