一、项目创建过程
1.下载SCICHART插件
2.选中第一个,确保引用中有我们要用的
二、示例代码
1.前端代码
XML
<Window x:Class="SciChart.Examples.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:s="http://schemas.abtsoftware.co.uk/scichart">
<Grid>
<s:SciChartSurface x:Name="sciChart">
<s:SciChartSurface.RenderableSeries>
<s:FastLineRenderableSeries x:Name="lineSeries">
<s:FastLineRenderableSeries.DataSeries>
<!-- 使用正确的数据系列类型 -->
<s:XyDataSeries x:Name="dataSeries"/>
</s:FastLineRenderableSeries.DataSeries>
</s:FastLineRenderableSeries>
</s:SciChartSurface.RenderableSeries>
</s:SciChartSurface>
</Grid>
</Window>
2.后端代码
cs
using System;
using System.Windows;
using SciChart.Charting.Model.DataSeries;
namespace SciChart.Examples
{
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
Loaded += MainWindow_Loaded;
}
private void MainWindow_Loaded(object sender, RoutedEventArgs e)
{
// 示例数据系列
var rand = new Random();
var dataSeries = new XyDataSeries<DateTime, double>();
// 生成随机数据
for (int i = 0; i < 100; i++)
{
dataSeries.Append(DateTime.Now.AddDays(i), rand.NextDouble() * 100);
}
// 将数据系列赋给渲染系列
lineSeries.DataSeries = dataSeries;
// 可选:自动调整视图范围
sciChart.ZoomExtents();
}
}
}