SoFunction
Updated on 2025-03-07

Detailed explanation of how to draw a surface chart in C#

This example describes the example of surface drawing of C# implementation in detail. This is one of the core drawing files codes. There are many comments in the code and are relatively detailed. I believe it will be helpful for beginners to learn and understand the technical points and difficulties in C# drawing.

The main functional codes for drawing a surface graph in C# are as follows:

using System;
using ;
using ;
using ;
using ;
using ;
using ;
using ;
using ;
namespace Draw a face chart
{
  public partial class Form1 : Form
  {
    public Form1()
    {
      InitializeComponent();
    }
    Graphics g;//Create Graphics object    private void button1_Click(object sender, EventArgs e)
    {
      Bitmap bt = new Bitmap(, );//Instantiate a Bitmap object      int flag = (-4 )/ 6;//The value-added of X-axis      g = (bt);//Instantiate Graphics object      Pen p = new Pen(, 1);//Set Pen object      (p, new Point(0, 0), new Point(0, -20));//Draw the Y axis      (p, new Point(0,  - 20), new Point( - 4,  - 20));//Draw the X-axis      //Declare an array for drawing colors      Color[] cl = new Color[] { , , , , , , Color .Tomato};
      int[] points = { 20,70,80,60,40,100,10};//Declare an array that calculates the peak of the trend      Point pt1 = new Point(0,  - 20 - points[0]);//Record the first point of drawing the quadrilateral      Point pt2 = new Point(0,  - 20);//Record the second point of the quadrilateral drawing      for (int i = 0; i <= 6; i++)//Draw the month and face chart through a for loop      {
        PointF p1 = new PointF(flag * i,  - 20);// Calculate the coordinates of the numbers for each month        //Draw the number of the month that shows the number        ((), new Font("Songyi", 9), new SolidBrush(), new PointF( - 2, ));
        //Record the third point of drawing the quadrilateral        Point pt3 = new Point(flag * i,  - 20);
        //Record the fourth point of the quadrilateral drawing        Point pt4 = new Point(flag * i,  - 20 - points[i]);
        Point[] pt={pt1,pt2,pt3,pt4};//Declare a Point array        (new SolidBrush(cl[i]), pt);//Fill the color of the quadrilateral        //When you continue to draw the next quadrilateral, the last two points of the previous quadrilateral are the starting points of the next quadrilateral        pt1 = pt4;
        pt2 = pt3;
      }
       = bt;//Show the drawn face chart    }

    private void Form1_Load(object sender, EventArgs e)
    {

    }
  }
}

Surface charts are a very popular chart style, and it is very convenient to display data. Reasonable application will greatly improve the visual effect of program data!