.NET Framework 4.5 中chart(图表)控件的使用

原创 2017年07月19日 15:04:01

优秀博客:

.net chart(图表)控件的使用-System.Windows.Forms.DataVisualization.dll


http://www.cnblogs.com/mooncher/p/3769619.html



http://blog.csdn.net/u010701641/article/details/50836628



功能强大的图表控件(chart 控件)包含于:Microsoft Chart Controls for Microsoft .NET Framework 4.5中


一、需在工程中加需要的引用.DLL文件


1. WinForm应用程序中要想使用该图表控件,需引用如下DLL:


System.Windows.Forms.DataVisualization.Design.dll


System.Windows.Forms.DataVisualization.dll


System.Windows.Forms.DataVisualization.xml


2. Web应用程序中要想使用该图表控件,需引用如下DLL:


System.Web.DataVisualization.dll


System.Web.DataVisualization.Design.dll


System.Web.DataVisualization.xml

文件一般保存于 C:\Windows\Microsoft.NET\Framework64\v4.0.30319目录下面。


为了画柱状图,添加以下程序




using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Windows.Forms;
using System.Windows.Forms.DataVisualization.Charting;
namespace WindowsFormsApplication2
{
partial class Form1
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;

/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}

#region Windows Form Designer generated code

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
System.Windows.Forms.DataVisualization.Charting.ChartArea chartArea1 = new System.Windows.Forms.DataVisualization.Charting.ChartArea();
System.Windows.Forms.DataVisualization.Charting.Legend legend1 = new System.Windows.Forms.DataVisualization.Charting.Legend();
System.Windows.Forms.DataVisualization.Charting.Series series1 = new System.Windows.Forms.DataVisualization.Charting.Series();
System.Windows.Forms.DataVisualization.Charting.Series series2 = new System.Windows.Forms.DataVisualization.Charting.Series();
this.chart1 = new System.Windows.Forms.DataVisualization.Charting.Chart();
((System.ComponentModel.ISupportInitialize)(this.chart1)).BeginInit();
this.SuspendLayout();
//chart1.Series["Series1"].ChartType = (SeriesChartType)Enum.Parse(typeof(SeriesChartType), chartTypeName, true);
//
// chart1
//
this.chart1.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(211)))), ((int)(((byte)(223)))), ((int)(((byte)(240)))));
this.chart1.BackGradientStyle = System.Windows.Forms.DataVisualization.Charting.GradientStyle.TopBottom;
this.chart1.BorderlineColor = System.Drawing.Color.FromArgb(((int)(((byte)(26)))), ((int)(((byte)(59)))), ((int)(((byte)(105)))));
this.chart1.BorderlineDashStyle = System.Windows.Forms.DataVisualization.Charting.ChartDashStyle.Solid;
this.chart1.BorderlineWidth = 2;
this.chart1.BorderSkin.SkinStyle = System.Windows.Forms.DataVisualization.Charting.BorderSkinStyle.Emboss;
chartArea1.Area3DStyle.Inclination = 15;
chartArea1.Area3DStyle.Rotation = 10;
chartArea1.Area3DStyle.WallWidth = 0;
chartArea1.AxisX.LabelStyle.Font = new System.Drawing.Font("Trebuchet MS", 8.25F, System.Drawing.FontStyle.Bold);
chartArea1.AxisX.LineColor = System.Drawing.Color.FromArgb(((int)(((byte)(64)))), ((int)(((byte)(64)))), ((int)(((byte)(64)))), ((int)(((byte)(64)))));
chartArea1.AxisX.MajorGrid.LineColor = System.Drawing.Color.FromArgb(((int)(((byte)(64)))), ((int)(((byte)(64)))), ((int)(((byte)(64)))), ((int)(((byte)(64)))));
chartArea1.AxisY.LabelStyle.Font = new System.Drawing.Font("Trebuchet MS", 8.25F, System.Drawing.FontStyle.Bold);
chartArea1.AxisY.LineColor = System.Drawing.Color.FromArgb(((int)(((byte)(64)))), ((int)(((byte)(64)))), ((int)(((byte)(64)))), ((int)(((byte)(64)))));
chartArea1.AxisY.MajorGrid.LineColor = System.Drawing.Color.FromArgb(((int)(((byte)(64)))), ((int)(((byte)(64)))), ((int)(((byte)(64)))), ((int)(((byte)(64)))));
chartArea1.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(64)))), ((int)(((byte)(165)))), ((int)(((byte)(191)))), ((int)(((byte)(228)))));
chartArea1.BackGradientStyle = System.Windows.Forms.DataVisualization.Charting.GradientStyle.TopBottom;
chartArea1.BackSecondaryColor = System.Drawing.Color.Transparent;
chartArea1.BorderColor = System.Drawing.Color.FromArgb(((int)(((byte)(64)))), ((int)(((byte)(64)))), ((int)(((byte)(64)))), ((int)(((byte)(64)))));
chartArea1.BorderDashStyle = System.Windows.Forms.DataVisualization.Charting.ChartDashStyle.Solid;
chartArea1.Name = "Default";
chartArea1.Position.Auto = false;
chartArea1.Position.Height = 92F;
chartArea1.Position.Width = 92F;
chartArea1.Position.X = 2F;
chartArea1.Position.Y = 3F;
chartArea1.ShadowColor = System.Drawing.Color.Transparent;
chartArea1.Name = "ChartArea1";
this.chart1.ChartAreas.Add(chartArea1);
legend1.Name = "Legend1";
this.chart1.Legends.Add(legend1);
this.chart1.Location = new System.Drawing.Point(51, 58);
this.chart1.Name = "chart1";
series1.BorderColor = System.Drawing.Color.FromArgb(((int)(((byte)(180)))), ((int)(((byte)(26)))), ((int)(((byte)(59)))), ((int)(((byte)(105)))));
series1.ChartArea = "ChartArea1";
series1.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.StackedArea100;
series1.Color = System.Drawing.Color.FromArgb(((int)(((byte)(220)))), ((int)(((byte)(65)))), ((int)(((byte)(140)))), ((int)(((byte)(240)))));
series1.Legend = "Legend1";
series1.Name = "Series1";
series2.BorderColor = System.Drawing.Color.FromArgb(((int)(((byte)(180)))), ((int)(((byte)(26)))), ((int)(((byte)(59)))), ((int)(((byte)(105)))));
series2.ChartArea = "ChartArea1";
series2.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.StackedArea100;
series2.Color = System.Drawing.Color.FromArgb(((int)(((byte)(220)))), ((int)(((byte)(252)))), ((int)(((byte)(180)))), ((int)(((byte)(65)))));
series2.Legend = "Legend1";
series2.Name = "Series2";
this.chart1.Series.Add(series1);
this.chart1.Series.Add(series2);
chart1.Series["Series1"].ChartType = (SeriesChartType)Enum.Parse(typeof(SeriesChartType), "StackedColumn", true);
chart1.Series["Series2"].ChartType = (SeriesChartType)Enum.Parse(typeof(SeriesChartType), "StackedColumn", true);
/* series1.ChartArea = "ChartArea1";
series1.Legend = "Legend1";
series1.Name = "Series1";
//series1.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.StackedArea100;
Random rd = new Random();
double[] num = new double[20];
for (int i = 0; i < 20; i++)
{
// chart1.Series["Series1"].Points.AddY(rd.Next(75, 170));
int valuey = rd.Next(25, 110);
DataPoint point = new DataPoint((i + 1), valuey);
series1.Points.Add(point);
}
this.chart1.Series.Add(series1);
Random rd2 = new Random();
//double[] num2 = new double[20];
for (int i = 0; i < 20; i++)
{
int valuey = rd2.Next(45, 140);
DataPoint point = new DataPoint((i + 1), valuey);
series2.Points.Add(point);
//chart1.Series["Series2"].Points.AddY(rd2.Next(75, 170));
}
series2.BorderColor = System.Drawing.Color.FromArgb(((int)(((byte)(180)))), ((int)(((byte)(26)))), ((int)(((byte)(59)))), ((int)(((byte)(105)))));
series2.ChartArea = "ChartArea1";
//series2.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.StackedArea100;
series2.Color = System.Drawing.Color.FromArgb(((int)(((byte)(220)))), ((int)(((byte)(252)))), ((int)(((byte)(180)))), ((int)(((byte)(65)))));
series2.Legend = "Legend1";
series2.Name = "Series2";
this.chart1.Series.Add(series2);*/
/*Random random = new Random();
for (int pointIndex = 0; pointIndex < 10; pointIndex++)
{
chart1.Series["Series1"].Points.AddY(random.Next(75, 170));
chart1.Series["Series2"].Points.AddY(random.Next(35, 125));
// chart1.Series["Series3"].Points.AddY(random.Next(45, 140));
// chart1.Series["Series4"].Points.AddY(random.Next(25, 110));
}*/
//this.chart1.Series.Add(series1);
//this.chart1.Series.Add(series2);
this.Load += new System.EventHandler(this.StackedChartType_Load);
this.chart1.Size = new System.Drawing.Size(396, 308);
this.chart1.TabIndex = 0;
this.chart1.Text = "chart1";
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(635, 424);
this.Controls.Add(this.chart1);
this.Name = "Form1";
this.Text = "Form1";
((System.ComponentModel.ISupportInitialize)(this.chart1)).EndInit();
this.ResumeLayout(false);

}

#endregion
private void StackedChartType_Load(object sender, System.EventArgs e)
{
// Populate series data
Random random = new Random();
for (int pointIndex = 0; pointIndex < 10; pointIndex++)
{
chart1.Series["Series1"].Points.AddY(random.Next(75, 170));
chart1.Series["Series2"].Points.AddY(random.Next(35, 125));
// chart1.Series["Series3"].Points.AddY(random.Next(45, 140));
// chart1.Series["Series4"].Points.AddY(random.Next(25, 110));
}

// Set selection
//comboBoxChartType.SelectedIndex = 2;
}
private System.Windows.Forms.DataVisualization.Charting.Chart chart1;
}
}









.NET chart控件使用方法

下面是下载地址:     控件:Microsoft .NET Framework 3.5 的 Microsoft 图表控件(Microsoft Chart Controls for Micros...
  • lumliang1234
  • lumliang1234
  • 2015年04月16日 17:06
  • 4746

C# WinForm开发系列之c# 通过.net自带的chart控件绘制饼图,柱形图和折线图的基础使用和扩展

一.需要实现的目标是: 1.将数据绑定到pie的后台数据中,自动生成饼图。 2.生成的饼图有详细文字的说明。 1.设置chart1的属性Legends中默认的Legend1的Enable为...
  • DannyIsCoder
  • DannyIsCoder
  • 2017年04月18日 10:08
  • 10852

asp.net使用chart控件简单制作柱状体、饼图总结

asp.net使用chart控件简单制作柱状体、饼图总结 1、  柱状图   前台代码:                                           ...
  • liucunguang2
  • liucunguang2
  • 2014年05月23日 18:02
  • 3476

asp.net Chart的使用介绍

安装MSChart 由于是和.NET3.5一起推出来的,所以只能在最新的开发环境中使用,需要.Net 3.5 Sp1和VS 2008的开发环境。 控件下载地址: Microsoft .NET ...
  • yan_yan_521
  • yan_yan_521
  • 2013年10月30日 09:01
  • 948

C#创建基本图表(Chart Controls)

在.NET环境下微软提供了强大了图表控件,并给多了很多实例,关于图表的基本元素。这里给了一个示例,开始学习图表控件。...
  • akof1314
  • akof1314
  • 2010年07月03日 15:25
  • 33988

微软图表控件MsChart的简单使用

       昨天在网上看到了微软发布了.NET 3.5框架下的图表控件,第一时间抓下来看了一下,发觉功能很强劲,基本上能想到的图表都可以使用它绘制出来,给图形统计和报表图形显示提供了很好的解决...
  • XueminXu
  • XueminXu
  • 2014年05月27日 10:05
  • 1374

微软发布.Net Framework 3.5下的 Chart 控件。

微软今天发布了Net Framework 3.5下的 Chart 控件,弥补了.Net平台下缺乏一个十分强力的图表控件。该图表控件支持多种图表,如饼图,柱状图,曲线图,散点图,雷达图,面积图,股票图等...
  • greenerycn
  • greenerycn
  • 2008年10月27日 20:46
  • 1902

VS2010与.NET4系列 15.内置的图表控件

今天介绍 .NET 4 中为 ASP.NET 和 Windows Forms 新增的内置图表控件支持。 ASP.NET 和 Windows Forms 的图表控件 在14个月以前,我在一篇博客日志上撰...
  • netatomy
  • netatomy
  • 2012年10月10日 01:23
  • 2121

10款好用的.NET图表控件推荐

概述:图形图表的可视化数据表现形式已成为一种趋势,本文推荐了10款非常好用的.NET图表控件,希望对广大.NET图表开发者能有所帮助。 在如今这个读图时代,图形图表的可视化数据表现形式已...
  • longshengguoji
  • longshengguoji
  • 2013年04月27日 20:45
  • 2431

最实用的5款数据可视化工具,教你玩转图表报表

我们收集了适合各个平台各种行业的多个图表和报表工具,这些工具中不乏有适用于.NET、Java、Flash、HTML5、Flex等平台的,也不乏有适用于常规图表报表、甘特图、流程图、金融图表、工控图表、...
  • Pokemogo
  • Pokemogo
  • 2017年12月21日 16:35
  • 131
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:.NET Framework 4.5 中chart(图表)控件的使用
举报原因:
原因补充:

(最多只允许输入30个字)