Demo of Microsoft Chart Controls for Microsoft .NET Framework 3.5
时间:2010-08-18
来源:会长
在手机上看
手机扫描阅读
控件介绍
http://www.cnblogs.com/greenerycn/archive/2008/10/27/microsoft-chart.htmlDemo展示






主要代码
代码
/*
* author:Joey Zhao
* date:2010-8-18
* describe: a simple demo of MsChart 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 MsChartDemo
{
public partial class FormChart : Form
{
private int _maxXValue;//横坐标最大值
private int _maxYValue;//纵坐标最大值
private SeriesChartType _chartType = SeriesChartType.Column;//显示样式
private bool _show3dStyle;//是否显示3D效果
private string _labelStyle = "Auto";//lableStyle用户属性值
private List<Entity> m_listXrayFlux = new List<Entity>();//假数据,测试用
//构造函数
public FormChart()
{
this.InitializeComponent();
_maxXValue = 10;
_maxYValue = 100;
this.InitControls();
this.BindData();
}
//绑定数据
private void BindData()
{
//绑定Series1
Random random = new Random();
for (int i = 0; i < 10; i++)
{
this.chart1.Series[0].Points.AddY(random.Next(0, 100));
}
//绑定Series3,Series3
List<MyEntity> list = new List<MyEntity>();
MyEntity ent = null;
for (int i = 0; i < 20; i++)
{
ent = new MyEntity();
ent.X = i;
ent.Y = random.Next(0, 100);
ent.Z = random.Next(0, 100);
list.Add(ent);
}
this.chart1.DataSource = list;
this.chart1.Series[2].XValueMember = "X";
this.chart1.Series[2].YValueMembers = "Y";
this.chart1.Series[1].XValueMember = "X";
this.chart1.Series[1].YValueMembers = "Z";
}
//初始化控件
private void InitControls()
{
//
//trackBarX控件
//
this.trackBarX.Minimum = _maxXValue;
this.trackBarX.Maximum = 100;
this.trackBarX.ValueChanged += delegate(object o, EventArgs e)
{
_maxXValue = this.trackBarX.Value;
this.UpDateSetting();
};
//
//trackBarY控件
//
this.trackBarY.Minimum = _maxYValue;
this.trackBarY.Maximum = 500;
this.trackBarY.ValueChanged += delegate(object o, EventArgs e)
{
_maxYValue = this.trackBarY.Value;
this.UpDateSetting();
};
//
//comboBoxStyle控件
//
this.comboBoxStyle.DropDownStyle = ComboBoxStyle.DropDownList;
string[] array = Enum.GetNames(typeof(SeriesChartType));
for (int i = 0; i < array.Length; i++)
{
this.comboBoxStyle.Items.Add(array[i]);
}
this.comboBoxStyle.Text = SeriesChartType.Column.ToString();
this.comboBoxStyle.SelectedIndexChanged += delegate(object o, EventArgs e)
{
if (this.comboBoxStyle.Text == string.Empty)
{
return;
}
_chartType = (SeriesChartType)Enum.Parse(typeof(SeriesChartType), this.comboBoxStyle.Text);
this.UpDateSetting();
};
//
//ComboBoxLableStyle控件
//
this.comboBoxLableStyle.Items.AddRange(
new object[] {"Auto", "Top", "Bottom", "Right",
"Left", "TopLeft", "TopRight", "BottomLeft", "BottomRight", "Center" });
this.comboBoxLableStyle.SelectedIndex = 0;
this.comboBoxLableStyle.DropDownStyle = ComboBoxStyle.DropDownList;
this.comboBoxLableStyle.SelectedIndexChanged += delegate(object o, EventArgs e)
{
_labelStyle = this.comboBoxLableStyle.Text;
this.UpDateSetting();
};
//
//Chart控件
//
this.chart1.Series[0].IsValueShownAsLabel = true;
this.chart1.Series[1].IsValueShownAsLabel = true;
this.chart1.ChartAreas[0].AxisX.Title = "ChartArea1";
this.chart1.ChartAreas[1].AxisX2.Title = "ChartArea2";
this.chart1.Series[0].XAxisType = AxisType.Secondary;//坐标样式
this.chart1.Series[0].YAxisType = AxisType.Secondary;//坐标样式
//
//3D按钮
//
this.button3D.Click += delegate(object o, EventArgs e)
{
_show3dStyle = !_show3dStyle;
this.UpDateSetting();
};
}
//更新Chart控件
private void UpDateSetting()
{
foreach (var item in this.chart1.Series)
{
item.ChartType = _chartType;
item["LabelStyle"] = _labelStyle;
}
this.chart1.ChartAreas[0].AxisX2.Maximum = _maxXValue;
this.chart1.ChartAreas[0].AxisY2.Maximum = _maxYValue;
this.chart1.ChartAreas[1].AxisX.Maximum = _maxXValue;
this.chart1.ChartAreas[1].AxisY.Maximum = _maxYValue;
this.chart1.ChartAreas[0].Area3DStyle.Enable3D = _show3dStyle;
this.chart1.ChartAreas[1].Area3DStyle.Enable3D = _show3dStyle;
}
}
class MyEntity
{
public int X
{
get;
set;
}
public int Y
{
get;
set;
}
public int Z
{
get;
set;
}
}
}
主要概念
- ChartArea:包括一组到两组横纵坐标,一个或多个Series放在CharArea上。一个Chart控件可以包含多个ChartArea
- Series:一组数据,包含了构成图形的一系列坐标点
相关阅读 更多
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28