A Preliminary Study on the chart control of winform

Source: Internet
Author: User

With the chart control, drawing is easy. You can set the attribute series as needed. You can add a series by drawing multiple lines. The charttype can be used to control the line, pie, or chart, and saveimage can be used to directly Save the image.

Another recommended connection: http://www.cnblogs.com/gaoweipeng/archive/2010/04/06/1704879.html

Using system;

Using system. Data;

Using system. test;

Using system. drawing;

Using system. Drawing. imaging;

Using system. Windows. forms;

Namespace chartdemo
{
Public partial class form2: Form
{
Public form2 ()
{
Initializecomponent ();
}

Private void form2_load (Object sender, eventargs E)
{
// Chart1.series.
Datatable dt = default (datatable );
Dt = createdatatable ();

// Set the chart data source
Chart1.datasource = DT;

// Set the Y axis of the chart.
Chart1.series [0]. yvaluemembers = "volume1 ";
Chart1.series [1]. yvaluemembers = "volume2 ";

// Set the corresponding item on the X axis of the chart.
Chart1.series [0]. xvaluemember = "date ";

// Bind data

Chart1.databind ();

// Save the image

Chart1.saveimage (@ "E: \ 1.bmp", imageformat. BMP );

}

Private datatable createdatatable ()
{
Datatable dt = new datatable ();

DT. Columns. Add ("date ");
DT. Columns. Add ("volume1 ");
DT. Columns. Add ("volume2 ");

Datarow Dr;
Dr = DT. newrow ();
Dr ["date"] = "Jan ";
Dr ["volume1"] = 3731;
Dr [& quot; volume2 & quot;] = 4101;
DT. Rows. Add (DR );

Dr = DT. newrow ();
Dr ["date"] = "FEB ";
Dr ["volume1"] = 6024;
Dr [& quot; volume2 & quot;] = 4324;
DT. Rows. Add (DR );

Dr = DT. newrow ();
Dr ["date"] = "Mar ";
Dr ["volume1"] = 4935;
Dr [& quot; volume2 & quot;] = 2935;
DT. Rows. Add (DR );

Dr = DT. newrow ();
Dr ["date"] = "APR ";
Dr ["volume1"] = 4466;
Dr [& quot; volume2 & quot;] = 5644;
DT. Rows. Add (DR );
Return DT;
}
}
}

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.