03-24 Winform圖表Chart

圖表主要分爲如下幾個部分:sql

一、Annotations--圖形註解集合,數據庫

二、ChartAreas--圖表區域集合,數組

三、Legends--圖例集合,工具

四、Series--圖表序列集合(即圖表數據對象集合),spa

五、Titles--圖標的標題集合。code

第一步:在Form1的工具箱中拖入一個chart圖表控件;orm

image

第二步:在圖表的屬性中,能夠修改每一個集合各自的屬性及樣式;對象

image

打開每一個集合,都會有各自的屬性;blog

Title集合:get

image

Series集合:

image

Annotations(圖表批註)集合:

image

第三步:經過linq to sql 鏈接數據庫,添加數據庫表xuesheng;

而後,在form1的Page_Load中數據綁定到chart1中,設置圖表顯示的樣式等。

using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Chart圖形
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        //插入圖表
        private void Form1_Load(object sender, EventArgs e)
        {
            DataClasses1DataContext context = new DataClasses1DataContext();
           // List<xuesheng> list = context.xuesheng.Take(5).ToList();//能夠使用枚舉類型
            xuesheng[] list1 = context.xuesheng.Take(5).ToArray();//也能夠使用chart.xuesheng數組類型
            chart1.DataSource = list1;
            chart1.Series["語文"].ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Bubble;//設置圖表類型(氣泡圖型)
            chart1.Series["語文"].XValueMember = "xingming";//設置x軸的數據源成員(列)
            chart1.Series["語文"].YValueMembers = "yuwen";//設置y軸的多個數據源成員(語文分數)
            chart1.Series["數學"].ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.FastLine;//設置圖表類型(掃描線型)
            chart1.Series["數學"].XValueMember = "xingming";//必須語文的x軸顯示的數據同樣
            chart1.Series["數學"].YValueMembers = "shuxue";//(數學分數)
        }
    }
}

效果圖:

image

相關文章
相關標籤/搜索