赞
踩
层级:
表:chart
线:Series
点:Points(DataPoint)
Series:图表序列->图表集合,就是最终看到的饼图、柱状图、线图、点图等构成的.
1.ChartArea:图表所属的绘图区域名称 2.ChartType:图表类型(柱形、饼形、线形、点形、折线图等,有多达几十种之多) 3.IsValueShownAsLabel:是否显示数据点标签,如果为true,在图表中显示每一个数据值 4.Label:数据点标签文本 5.LabelFormat:数据点标签文本格式 6.LabelAngle:标签字体角度 7.Legend:当前数据系列(图表)使用的图例名称 8.Name:数据系列的名称 9.Palette:数据系列(图表)外观定义 10.Points:数据点集合,不添加这个,窗体在初使化后什么都没有 11.XValueMember:横坐标绑定的数据源 12.XValueType:横坐标数字的类型,默认为auto,即根据传入的数据自动规定类型 13.YValueMembers:纵坐标绑定的数据源 14.YValueType:纵坐标数字的类型默认为auto,即根据传入的数据自动规定类型 15.XAxisType:只是所要使用的坐标轴是主坐标还是副坐标,它有两个取值,Primary和Sencondary 16.YAxisType: 17. 映射区(TooTip):鼠标放在数据点上出现的小提示,建议用代码控制
在一个区域里有
<Grid Name="Simon">
</Grid>
在C#文件源码:
#region 实时折线图 public Timer threadTimer { get; private set; } public Chart chart= null; private List<string> cherry = new List<string>() { "33", "75", "60", "98", "67", "88", "39", "45", "13", "22", "45", "80" }; private List<DateTime> LsTimeRT = new List<DateTime>(); public void InitTimer() { threadTimer = new System.Threading.Timer(new TimerCallback(TimerUp), null, 1000, 500); } private void InitChart() { //创建一个图标 this.chart = new Chart(); //设置图标的宽度和高度 chart.Width = 580; chart.Height = 380; chart.Margin = new Thickness(100, 5, 10, 5); //是否启用打印和保持图片 chart.ToolBarEnabled = false; //设置图标的属性 chart.ScrollingEnabled = true;//ccj false;//是否启用或禁用滚动 chart.View3D = false; //ccj true;//3D效果显示 //创建一个标题的对象 Title title = new Title(); //设置标题的名称 title.Text = "实时曲线"; title.Padding = new Thickness(0, 10, 5, 0); //向图标添加标题 chart.Titles.Add(title); //初始化一个新的Axis Axis xaxis = new Axis(); //设置Axis的属性 //图表的X轴坐标按什么来分类,如时分秒 xaxis.IntervalType = IntervalTypes.Milliseconds; //图表的X轴坐标间隔如2,3,20等,单位为xAxis.IntervalType设置的时分秒。 xaxis.Interval = 2000; //设置X轴的时间显示格式为7-10 11:20 xaxis.ValueFormatString = "MM秒"; //给图标添加Axis chart.AxesX.Add(xaxis); Axis yAxis = new Axis(); //设置图标中Y轴的最小值永远为0 yAxis.AxisMinimum = 0; //设置图表中Y轴的后缀 yAxis.Suffix = "斤"; chart.AxesY.Add(yAxis); // 创建一个新的数据线。 DataSeries dataSeries = new DataSeries(); // 设置数据线的格式。 dataSeries.LegendText = "樱桃"; dataSeries.RenderAs = RenderAs.Spline;//折线图 dataSeries.XValueType = ChartValueTypes.DateTime; // 添加数据线到数据序列。 chart.Series.Add(dataSeries); //将生产的图表增加到Grid,然后通过Grid添加到上层Grid. Grid gr = new Grid(); gr.Children.Add(chart); Simon.Children.Clear(); Simon.Children.Add(gr); } private void TimerUp(object state) { DateTime now = DateTime.Now; LsTimeRT.Add(now); App.Current.Dispatcher.Invoke((Action)(() => { this.chart.Series[0].DataPoints.Clear(); // 设置数据点 DataPoint dataPoint; int ii = 30; if (LsTimeRT.Count < ii) { for (int i = 0; i < LsTimeRT.Count; i++) { // 创建一个数据点的实例。 dataPoint = new DataPoint(); // 设置X轴点 dataPoint.XValue = LsTimeRT[i]; //设置Y轴点 dataPoint.YValue = double.Parse(cherry[i % 12]); dataPoint.MarkerSize = 8; //dataPoint.Tag = tableName.Split('(')[0]; //设置数据点颜色 // dataPoint.Color = new SolidColorBrush(Colors.LightGray); dataPoint.MouseLeftButtonDown += new MouseButtonEventHandler(dataPoint_MouseLeftButtonDown); //添加数据点 this.chart.Series[0].DataPoints.Add(dataPoint); } } else { List<DateTime> llt = new List<DateTime>(); for (int i = LsTimeRT.Count - ii; i < LsTimeRT.Count; i++) { // 创建一个数据点的实例。 dataPoint = new DataPoint(); // 设置X轴点 dataPoint.XValue = LsTimeRT[i]; //设置Y轴点 dataPoint.YValue = double.Parse(cherry[i % 12]); dataPoint.MarkerSize = 8; //dataPoint.Tag = tableName.Split('(')[0]; //设置数据点颜色 // dataPoint.Color = new SolidColorBrush(Colors.LightGray); dataPoint.MouseLeftButtonDown += new MouseButtonEventHandler(dataPoint_MouseLeftButtonDown); //添加数据点 this.chart.Series[0].DataPoints.Add(dataPoint); } } })); } private void ButRealTimeSpline_Click(object sender, RoutedEventArgs e) { Simon.Children.Clear(); InitChart(); InitTimer(); } #endregion
ButRealTimeSpline_Click :按钮事件触发
threadTimer :定时器
TimerUp:定时器回调函数
chart:图
cherry :数据
结果:
赞
踩
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。