Get the App
SLTechnology News&Howtos  ›  Development  › 

How to draw bar chart and line chart in C #

Shulou Source: shulou.com Published: 2022-06-01 18:19:01 10月02日 Update

This article is about how C # draws histograms and line charts. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.

The details are as follows

The running effect is as follows:

In fact, it is not difficult to design the bar chart and line chart above, mainly the calculation of each coordinate, which is completely fine work. First of all, a tabControl control is added to the form to toggle the display of bar chart and line chart, display bar chart in tabPage1 and line chart in tabPage2. Then define the Paint event in their respective Page page properties, as you can see in the following code.

The code is as follows:

Add a header file:

Using System.Drawing.Drawing2D

Paint event of tabPage1 (bar chart):

Private void tabPage1_Paint (object sender, PaintEventArgs e) {BackColor = Color.White; / / title Graphics g = tabPage1.CreateGraphics (); Font f = new Font ("Song style", 24, FontStyle.Regular); Pen p = new Pen (Color.Blue); g.DrawString ("Registration and examination Statistics histogram", f, p.Brush, 200,20) / / draw the form for (int I = 0; I

Tags: Chart column part number Song style face Statistics event content break Line number Red Green Category Code year-round Graphics text more title Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Redmi NVidia Shulou Tech Info Docker MySQL