When our software requires various pie charts and bar charts to represent data, we may think of using graphical controls or third-party controls in Offices, but most of the third-party controls need to be registered now, some free controls have developer tags. However, graphical controls using Offices cannot be well controlled in the program, and the ease of use is also low, so here I will show how to use GDI + in C # To connect the pie chart and bar chart to the database to display data.
Using System;
Using System. IO; // used for File Access
Using System. Data; // used for Data access
Using System. Drawing; // provides basic functions for Drawing GDI + graphics.
Using System. Drawing. Text; // provides advanced functions for Drawing GDI + graphics.
Using System. Drawing. Drawing2D; // provides advanced 2D and vector graphics Functions.
Using System. Drawing. Imaging; // provides advanced functions for Drawing GDI + graphics.
Namespace BaseLayer
{
Public class PieChart
{
Public PieChart ()
{
}
// Render is the big title of the graph. The title of the graph, the width of the graph, the graph length, the dataset of the pie chart, and the data to be expressed by the dataset of the pie chart.
Public Image Render (string title, string subTitle, int width, int height, DataSet chartData, int DataLine)
{
Const int SIDE_LENGTH = 400;
Const int PIE_DIAMETER = 200;
DataTable dt = chartData. Tables [0];