基本信息
源码名称:C# winform 折线统计图 例子源码下载(長條圖)
源码大小:0.04M
文件格式:.rar
开发语言:C#
更新时间:2016-03-19
   友情提示:(无需注册或充值,赞助后即可获取资源下载链接)

     嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300

本次赞助数额为: 2 元 
   源码介绍

MS Chart Control 學習手記 - 長條圖

客戶希望可以針對資料庫裡面的資料產生出曲線圖、直條圖、橫條圖、立體直條圖、立體橫條圖、圓餅圖、立體圓餅圖




using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Windows.Forms.DataVisualization.Charting;

namespace chart
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            Chart Chart1 = new Chart();
            Chart1.ChartAreas.Add("ChartArea1"); //圖表區域集合
            Chart1.Series.Add("隨機數字"); //數據序列集合

            //設定 Chart
            Chart1.Width = 700;
            Chart1.Height = 400;
            
            //設置網格的顏色
            chart1.ChartAreas["ChartArea1"].AxisX.MajorGrid.LineColor = Color.LightGray;
            chart1.ChartAreas["ChartArea1"].AxisY.MajorGrid.LineColor = Color.LightGray;

            //設置坐標軸名稱
            chart1.ChartAreas["ChartArea1"].AxisX.Title = "隨機數字";
            chart1.ChartAreas["ChartArea1"].AxisY.Title = "數值";

            //啟用3D顯示
            chart1.ChartAreas["ChartArea1"].Area3DStyle.Enable3D = false;


            //////////////////////Series屬性設置///////////////////////////

            //設置顯示類型-線型
            //chart1.Series["隨機數字"].ChartType = SeriesChartType.Line;
            chart1.Series["隨機數字"].ChartType = SeriesChartType.Column;

            //設置坐標軸Value顯示類型
            chart1.Series["隨機數字"].XValueType = ChartValueType.Time;

            //是否顯示標籤的數值
            chart1.Series["隨機數字"].IsValueShownAsLabel = true;


            chart1.Series["隨機數字"].MarkerStyle = MarkerStyle.Circle;     //設置標記圖案


            chart1.Series["隨機數字"].Color = Color.Red;                //設置圖案顏色

            chart1.Series["隨機數字"].BorderWidth = 3;                  //設置圖案的寬度

            chart1.Series["隨機數字"].ShadowColor = Color.DarkGray;      // 陰影的顏色

            chart1.Series["隨機數字"].ShadowOffset = 2;                  // 陰影位置的角度


            //添加隨機數字
            Random rd = new Random();
            for (int i = 1; i < 20; i )
            {
                chart1.Series["隨機數字"].Points.AddXY(i, rd.Next(100));
            }

            //string[] xValues = { "數值1", "數值2" };
            //string[] titleArr = { "活動1", "活動2" };
            //int[] yValues = { 269000, 94 };
            //int[] yValues2 = { 120300, 116 };

            ////ChartAreas,Series,Legends 基本設定--------------------------------------------------
            //Chart Chart1 = new Chart();
            //Chart1.ChartAreas.Add("ChartArea1"); //圖表區域集合
            //Chart1.Series.Add("Series1"); //數據序列集合
            //Chart1.Series.Add("Series2");
            //Chart1.Legends.Add("Legends1"); //圖例集合

            ////設定 Chart
            //Chart1.Width = 700;
            //Chart1.Height = 400;
            //Title title = new Title();
            //title.Text = "長條圖";
            //title.Alignment = ContentAlignment.MiddleCenter;
            //title.Font = new System.Drawing.Font("Trebuchet MS", 14F, FontStyle.Bold);
            //Chart1.Titles.Add(title);

            ////設定 ChartArea----------------------------------------------------------------------
            //Chart1.ChartAreas["ChartArea1"].Area3DStyle.Enable3D = true; //3D效果
            //Chart1.ChartAreas["ChartArea1"].Area3DStyle.IsClustered = true; //並排顯示
            //Chart1.ChartAreas["ChartArea1"].Area3DStyle.Rotation = 40; //垂直角度
            //Chart1.ChartAreas["ChartArea1"].Area3DStyle.Inclination = 50; //水平角度
            //Chart1.ChartAreas["ChartArea1"].Area3DStyle.PointDepth = 30; //數據條深度
            //Chart1.ChartAreas["ChartArea1"].Area3DStyle.WallWidth = 0; //外牆寬度
            //Chart1.ChartAreas["ChartArea1"].Area3DStyle.LightStyle = LightStyle.Realistic; //光源
            //Chart1.ChartAreas["ChartArea1"].BackColor = Color.FromArgb(240, 240, 240); //背景色
            //Chart1.ChartAreas["ChartArea1"].AxisX2.Enabled = AxisEnabled.False; //隱藏 X2 標示
            //Chart1.ChartAreas["ChartArea1"].AxisY2.Enabled = AxisEnabled.False; //隱藏 Y2 標示
            //Chart1.ChartAreas["ChartArea1"].AxisY2.MajorGrid.Enabled = false;   //隱藏 Y2 軸線
            ////Y 軸線顏色
            //Chart1.ChartAreas["ChartArea1"].AxisY.MajorGrid.LineColor = Color.FromArgb(150, 150, 150);
            ////X 軸線顏色
            //Chart1.ChartAreas["ChartArea1"].AxisX.MajorGrid.LineColor = Color.FromArgb(150, 150, 150);
            //Chart1.ChartAreas["ChartArea1"].AxisY.LabelStyle.Format = "#,###";
            ////Chart1.ChartAreas["ChartArea1"].AxisY2.Maximum = 160;
            ////Chart1.ChartAreas["ChartArea1"].AxisY2.Interval = 20;

            ////設定 Legends------------------------------------------------------------------------                
            //Chart1.Legends["Legends1"].DockedToChartArea = "ChartArea1"; //顯示在圖表內
            ////Chart1.Legends["Legends1"].Docking = Docking.Bottom; //自訂顯示位置
            //Chart1.Legends["Legends1"].BackColor = Color.FromArgb(235, 235, 235); //背景色
            ////斜線背景
            //Chart1.Legends["Legends1"].BackHatchStyle = ChartHatchStyle.DarkDownwardDiagonal;
            //Chart1.Legends["Legends1"].BorderWidth = 1;
            //Chart1.Legends["Legends1"].BorderColor = Color.FromArgb(200, 200, 200);

            ////設定 Series-----------------------------------------------------------------------
            //Chart1.Series["Series1"].ChartType = SeriesChartType.Column; //直條圖
            ////Chart1.Series["Series1"].ChartType = SeriesChartType.Bar; //橫條圖
            //Chart1.Series["Series1"].Points.DataBindXY(xValues, yValues);
            //Chart1.Series["Series1"].Legend = "Legends1";
            //Chart1.Series["Series1"].LegendText = titleArr[0];
            //Chart1.Series["Series1"].LabelFormat = "#,###"; //金錢格式
            //Chart1.Series["Series1"].MarkerSize = 8; //Label 範圍大小
            //Chart1.Series["Series1"].LabelForeColor = Color.FromArgb(0, 90, 255); //字體顏色
            ////字體設定
            //Chart1.Series["Series1"].Font = new System.Drawing.Font("Trebuchet MS", 10, System.Drawing.FontStyle.Bold);
            ////Label 背景色
            //Chart1.Series["Series1"].LabelBackColor = Color.FromArgb(150, 255, 255, 255);
            //Chart1.Series["Series1"].Color = Color.FromArgb(240, 65, 140, 240); //背景色
            //Chart1.Series["Series1"].IsValueShownAsLabel = true; // Show data points labels

            //Chart1.Series["Series2"].Points.DataBindXY(xValues, yValues2);
            //Chart1.Series["Series2"].Legend = "Legends1";
            //Chart1.Series["Series2"].LegendText = titleArr[1];
            //Chart1.Series["Series2"].LabelFormat = "#,###"; //金錢格式
            //Chart1.Series["Series2"].MarkerSize = 8; //Label 範圍大小
            //Chart1.Series["Series2"].LabelForeColor = Color.FromArgb(255, 103, 0);
            //Chart1.Series["Series2"].Font = new System.Drawing.Font("Trebuchet MS", 10, FontStyle.Bold);
            //Chart1.Series["Series2"].LabelBackColor = Color.FromArgb(150, 255, 255, 255);
            //Chart1.Series["Series2"].Color = Color.FromArgb(240, 252, 180, 65); //背景色
            //Chart1.Series["Series2"].IsValueShownAsLabel = true; //顯示數據
        }
    }
}