Use C # and GDI + to draw a bar chart (Data painting can be exported from the database)

Source: Internet
Author: User

Use C # and GDI + to draw a bar chart (Data painting can be exported from the database)

Return at night and draw out the variable name in a hurry. The figure is as follows:

Public void Bind ()
{
// Create a canvas
Bitmap bm = new Bitmap (240,210 );
// Draw a chart on the newly created canvas
Graphics bp = Graphics. FromImage (bm );
// Set the background color of bp to Beige.
Bp. Clear (Color. Beige );
// Create a data source, which is an array
Int [] a1 = {20, 40, 60, 80, 100,120,140,160 };
Int [] a2 = {40,60, 80,100,120,140,160,180 };
Bp. DrawRectangle (Pens. Black, 1, 1, 230,205 );
// Draw a bar chart cyclically
For (int I = 0; I <a1.Length; I ++)
{
// Fill the graph (coloring, starting point X, starting point Y, width, and height)
Bp. FillRectangle (new SolidBrush (Color. Blue), (I * 30) + 5,-a1 [I], 5, a1 [I] + 5 );
// Fill the border (coloring, starting point X, starting point Y, width, and height)
Bp. DrawRectangle (Pens. Black, (I * 30) + 5,200-a1 [I], 5, a1 [I] + 5 );
}
// Bar chart 2
For (int I = 0; I <a2.Length; I ++)
{
Bp. FillRectangle (new SolidBrush (Color. Red), (I * 30) +-a2 [I], 5, a2 [I] + 5 );
Bp. DrawRectangle (Pens. Black, (I * 30) +-a2 [I], 5, a2 [I] + 5 );
}
// Output to IE in gif format
Bm. Save (Response. OutputStream, ImageFormat. Gif );
}

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.