工程创建
1.创建WPF工程
2.创建一个文件夹lib
3.将WPFVisifire.Charts.dll添加进lib文件夹
4.添加引用-》浏览 选择 WPFVisifire.Charts.dll
使用:
<Window x:Class="testCharts.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="MainWindow" Height="350" Width="525"> <Grid x:Name="LayoutRoot"> </Grid> </Window> using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes; using Visifire.Charts; namespace testCharts { /// <summary> /// MainWindow.xaml 的交互逻辑 /// </summary> public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); // Create a new DateTime object dt = new List<DateTime>(); // Populate DateTime collection dt.Add(DateTime.Parse("2010-02-03 12:02:44")); dt.Add(DateTime.Parse("2010-02-03 12:03:44")); dt.Add(DateTime.Parse("2010-02-03 12:04:44")); dt.Add(DateTime.Parse("2010-02-03 12:05:44")); dt.Add(DateTime.Parse("2010-02-03 12:06:44")); dt.Add(DateTime.Parse("2010-02-03 12:07:44")); dt.Add(DateTime.Parse("2010-02-03 12:08:44")); // Create a new Visifire Chart CreateChart(); } /// <summary> /// Function to create a chart /// </summary> public void CreateChart() { // Create a new instance of Chart Chart chart = new Chart(); // Set chart properties chart.ScrollingEnabled = true; chart.View3D = false; // Create a new instance of Title Title title = new Title(); // Set title property title.Text = "Visifire DateTime Axis Chart"; // Add title to Titles collection chart.Titles.Add(title); // Create a new Axis Axis axis = new Axis(); // Set axis properties axis.IntervalType = IntervalTypes.Seconds; axis.ValueFormatString = "MMdd hh:mm"; axis.Interval = 60; // Add axis to AxesX collection chart.AxesX.Add(axis); for (Int32 j = 0; j < 2; j++) { // Create a new instance of DataSeries DataSeries dataSeries = new DataSeries(); // Set DataSeries properties //dataSeries.RenderAs = RenderAs.Area; dataSeries.RenderAs = RenderAs.Column; dataSeries.XValueType = ChartValueTypes.DateTime; dataSeries.XValueFormatString = "yyyyMMdd hh:mm:ss"; //Create a DataPoint DataPoint dataPoint; for (int i = 0; i < 6; i++) { // Create a new instance of DataPoint dataPoint = new DataPoint(); // Set XValue for a DataPoint dataPoint.XValue = dt[i]; // Set YValue for a DataPoint- dataPoint.YValue = rand.Next(10, 100); // Add dataPoint to DataPoints collection dataSeries.DataPoints.Add(dataPoint); //dataSeries.Name = "11"; } // Add dataSeries to Series collection. chart.Series.Add(dataSeries); } // Add chart to LayoutRoot LayoutRoot.Children.Add(chart); } /// <summary> /// Create a random class variable /// </summary> Random rand = new Random(DateTime.Now.Millisecond); List<DateTime> dt; } }