微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Silverlight调用Visfire开源图表组件的源代码

Silverlight调用Visfire开源图表组件的源代码

using System; using System.Collections.Generic; using System.Linq; using System.Net; using System.Windows; using System.Windows.Controls; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Animation; using System.Windows.Shapes; using Visifire.Charts; namespace SL { public partial class VisifireTest : UserControl { public Visifiretest() { InitializeComponent(); List<DateTime> updateTime = new List<DateTime>() { new DateTime(2010,2,01,7,11,03),new DateTime(2010,3,12,4,13,5,14,6,15,16,8,17,9,18,03) }; List< string> value = new List< string>() { " 20"," 25"," 40"," 55"," 67"," 74"," 88"," 94" }; List< string> value1 = new List< string>() { " 33"," 44"," 48"," 15"," 70"," 56"," 77"," 5" }; List< string> value2 = new List< string>() { " 10"," 81"," 66"," 60"," 12"," 100" }; List< object> valueList = new List< object> { value,value1,value2 }; CreateChart(" 内存使用率",updateTime,valueList," %",1,IntervalTypes.Minutes); } public void CreateChart( string tableName,List<DateTime> updateTime,List< object> valueList,string rihgtStr,int chartInterval,IntervalTypes intervaltype) { Chart chart = new Chart(); //创建一个图表 /* 设置图表属性 */ chart.Width = 500; chart.Height = 400; chart.ToolBarEnabled = true; chart.ScrollingEnabled = false; chart.View3D = true; Title title = new Title() { Text = tableName,Padding = new Thickness(0,10,0) }; //图表标题 chart.Titles.Add(title); //添加标题 Axis xAxis = new Axis(); //创建X轴 xAxis.IntervalType = intervaltype; //X轴分类类型,小时*分*秒 xAxis.Interval = chartInterval; //X轴坐标间隔距离 xAxis.ValueFormatString = " hh:mm:ss"; //X轴时间显示格式 chart.AxesX.Add(xAxis); //为图表添加X轴 Axis yAxis = new Axis(); //创建Y轴 yAxis.Suffix = rihgtStr; //Y轴后缀% yAxis.AxisMinimum = 0; //Y轴最小值为0 chart.AxesY.Add(yAxis); //为图表添加Y轴 for ( int i = 0; i < valueList.Count; i++) { DataSeries dataSeries = new DataSeries(); //创建数据线 dataSeries.RenderAs = RenderAs.Line; // 数据线显示类型为线型 dataSeries.XValueType = ChartValueTypes.DateTime; //设置X轴的类型为日期类型 List&lt; string> value = (List< string>)valueList[i]; for ( int j = 0; j &lt; updateTime.Count; j++) { DataPoint dataPoint = new DataPoint(); //创建数据点 dataPoint.XValue = updateTime[j]; //设置数据点X轴的值; dataPoint.YValue = double.Parse( value[j]); //设置Y轴值 dataPoint.MarkerSize = 8; //设置数据点的大小 dataPoint.MouseLeftButtonDown += new MouseButtonEventHandler(dataPoint_MouseLeftButtonDown); //数据点的鼠标单击事件 dataSeries.DataPoints.Add(dataPoint); //为数据线添加数据点 } chart.Series.Add(dataSeries); //为图表添加数据线 } LayoutRoot.Children.Add(chart); } void dataPoint_MouseLeftButtonDown( object sender,MouseButtonEventArgs e) { } } }

 

希望对大家有用~

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐