北京动点飞扬软件

近七年行业项目解决方案、专注WPF外包、SaaS外包、GoLang外包、H5外包、微信小程序外包、UE4外包、U3D外包等 案例丰富 — 您最值得信赖的合作伙伴 — 可签公司合同
  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

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,01,7,12,03),
                new DateTime(2010,4,01,7,13,03),
                new DateTime(2010,5,01,7,14,03),
                new DateTime(2010,6,01,7,15,03), 
                new DateTime(2010,7,01,7,16,03), 
                new DateTime(2010,8,01,7,17,03),
                new DateTime(2010,9,01,7,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", "67", "12", "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, 5, 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<string> value = (List<string>)valueList[i];
                for (int j = 0; j < 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)
        {

        }

    }
}

 

希望对大家有用~