LightningChart Ultimate使用教程:在WPF中绘制点线数据

原创|使用教程|编辑:郝浩|2013-10-30 09:30:47.000|阅读 848 次

概述:本教程讲述如何使用图表工具LightningChartUltimate PointLineSeries系列描绘变量区间点线数据。

相关链接:

本教程讲述如何使用图表工具LightningChartUltimate PointLineSeries系列描绘变量区间点线数据。

学习该教程,你需要具备:

  • 基本C#和Visual Studio 2010知识
  • 安装LightningChartUltimate v5.1 (.NET4)
  • Visual Studio 2010或更高环境

1、添加LightningChartUltimate控件

建立一个WPF应用程序。在e Visual Studio工具栏中拖放组件"LightningChartUltimate"到表格窗口编辑器。

LightningChart Ultimate组件

窗口编辑器如下图:

LightningChart Ultimate窗口编辑器

代码如下:

<Window x:Class="Arction_tutorial1.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"
xmlns:lcu="http://www.arction.com/schemas/">
<Grid UseLayoutRounding="True">
<lcu:LightningChartUltimate HorizontalAlignment="Stretch"
Name="lightningChartUltimate1" VerticalAlignment="Stretch" Margin="0" />
</Grid>
</Window>

2、初始化LightningChart组件

编辑MainWindow.xaml.cs源代码,用自定义外观设置和随机数据初始化。代码如下:

/* Tutorial:
* Simple LightningChart WPF application
*/

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 Arction.WPF.LightningChartUltimate;
using Arction.WPF.LightningChartUltimate.Views.ViewXY;
using Arction.WPF.LightningChartUltimate.SeriesXY;
using Arction.WPF.LightningChartUltimate.Axes;

//Make sure to use namespace similar to project name
namespace Arction_tutorial1
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{

public MainWindow()
{
InitializeComponent();
InitializeChart();
}

private void InitializeChart()
{
//Initialize chart
lightningChartUltimate1.BeginUpdate();

//Get XY view
ViewXY chartView = lightningChartUltimate1.ViewXY;

//Get default x-axis and set the range and ValueType
AxisX axisX = chartView.XAxes[0];
axisX.SetRange(0, 20);
axisX.ValueType = AxisValueType.Number;

//Get default y-axis and set the range.
AxisY axisY = chartView.YAxes[0];
axisY.SetRange(0, 100);

//Add point line series
PointLineSeries pls = new PointLineSeries(chartView, axisX, axisY);
pls.PointsVisible = true;

//Generate random data
Random rand = new Random();
const double dInterval = 1;
int iPointCount = (int)((axisX.Maximum - axisX.Minimum) / dInterval) + 1;
SeriesPoint[] aPoints = new SeriesPoint[iPointCount];
for (int iPoint = 0; iPoint < iPointCount; iPoint++)
{
aPoints[iPoint].X = (double)iPoint;
aPoints[iPoint].Y = 100.0 * rand.NextDouble();
}
//Assign the data for the point line series
pls.Points = aPoints;

//Add series to the PointLineSeries container in the view
chartView.PointLineSeries.Add(pls);

//Apply chart property changes, which causes chart to be painted
lightningChartUltimate1.EndUpdate();
}
}
}

编译并运行这个程序,结果如下图所示:

LightningChart Ultimate主窗口

下载地址:LightningChartUltimate



标签:

本站文章除注明转载外,均为本站原创或翻译。欢迎任何形式的转载,但请务必注明出处,尊重他人劳动成果

文章转载自:慧都控件网

登录 慧都网发表评论


暂无评论...

为你推荐

  • 推荐视频
  • 推荐活动
  • 推荐产品
  • 推荐文章
  • 慧都慧问
相关厂商
相关产品
LightningChart Ultimate SDK

LightningChart Ultimate是最快的.NET和Windows 2D和3D测量、管理和研发数据可视化SDK。

购物车 在线客服 在线QQ 电话咨询
400-700-1020
反馈
在线客服系统
live chat