SciChart® the market leader in Fast WPF Charts, WPF 3D Charts, iOS Chart, Android Chart and JavaScript Chart Components
SciChart WPF ships with hundreds of WPF Chart Examples which you can browse, play with, view the source-code and even export each WPF Chart Example to a stand-alone Visual Studio solution. All of this is possible with the new and improved SciChart WPF Examples Suite, which ships as part of the SciChart WPF SDK.
The Realtime 3D Point Cloud demo shows how to use the ScatterRenderableSeries3D type to render a 3D Point-Cloud chart with two-dimensional textures.
The Point-Cloud chart provides a high performance solution suitable for many thousands or hundreds of thousands of 3D markers, useful for particle physics visualisation, Ion-optics or NBody simulations.
Scatter points can be colored individually, programmatically selected and scaled using the PointMetadata3D class. PointMetadata also allows you to tag individual scatter points with a business object of any type.
The C#/WPF source code for the WPF 3D Chart RealTime 3D Point Cloud Example example is included below (Scroll down!).
Did you know you can also view the source code from one of the following sources as well?
<UserControl x:Class="SciChart.Examples.Examples.Charts3D.CreateRealtime3DCharts.CreateRealTime3DPointCloudChart"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:s3D="http://schemas.abtsoftware.co.uk/scichart3D"
xmlns:ext="http://schemas.abtsoftware.co.uk/scichart/exampleExternals"
Unloaded="CreateRealTime3DPointCloudChart_OnUnloaded"
mc:Ignorable="d"
d:DesignHeight="400"
d:DesignWidth="600">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<ext:SciChart3DInteractionToolbar TargetSurface="{Binding Source={x:Reference Name=sciChart}}">
<ext:FlyoutSeparator Background="#444"/>
<ToggleButton x:Name="StartButton" Click="StartButton_Click" Style="{StaticResource PlayButtonStyle}" Padding="4"/>
<ToggleButton x:Name="PauseButton" Click="PauseButton_Click" Style="{StaticResource PauseButtonStyle}" Padding="7"/>
<ToggleButton x:Name="ResetButton" Click="ResetButton_Click" Style="{StaticResource StopButtonStyle}" Padding="7"/>
</ext:SciChart3DInteractionToolbar>
<s3D:SciChart3DSurface x:Name="sciChart" Grid.Column="1" WorldDimensions="200,100,200" BorderThickness="0">
<s3D:SciChart3DSurface.Camera>
<s3D:Camera3D ZoomToFitOnAttach="True"/>
</s3D:SciChart3DSurface.Camera>
<s3D:SciChart3DSurface.RenderableSeries>
<s3D:ScatterRenderableSeries3D x:Name="ScatterRenderableSeries3D">
<s3D:ScatterRenderableSeries3D.PointMarker>
<s3D:EllipsePointMarker3D Fill="#77ADFF2F"/>
</s3D:ScatterRenderableSeries3D.PointMarker>
</s3D:ScatterRenderableSeries3D>
</s3D:SciChart3DSurface.RenderableSeries>
<s3D:SciChart3DSurface.XAxis>
<s3D:NumericAxis3D GrowBy="0.1, 0.1" AutoRange="Once"/>
</s3D:SciChart3DSurface.XAxis>
<s3D:SciChart3DSurface.YAxis>
<s3D:NumericAxis3D GrowBy="0.1, 0.1" AutoRange="Once" NegativeSideClipping="VisibleRange" PositiveSideClipping="VisibleRange" />
</s3D:SciChart3DSurface.YAxis>
<s3D:SciChart3DSurface.ZAxis>
<s3D:NumericAxis3D GrowBy="0.1, 0.1" AutoRange="Once"/>
</s3D:SciChart3DSurface.ZAxis>
</s3D:SciChart3DSurface>
</Grid>
</UserControl>
// *************************************************************************************
// SCICHART® Copyright SciChart Ltd. 2011-2022. All rights reserved.
//
// Web: http://www.scichart.com
// Support: support@scichart.com
// Sales: sales@scichart.com
//
// CreateRealTime3DPointCloudChart.xaml.cs is part of the SCICHART® Examples. Permission is hereby granted
// to modify, create derivative works, distribute and publish any part of this source
// code whether for commercial, private or personal use.
//
// The SCICHART® examples are distributed in the hope that they will be useful, but
// without any warranty. It is provided "AS IS" without warranty of any kind, either
// expressed or implied.
// *************************************************************************************
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Threading;
using SciChart.Charting.Model.DataSeries;
using SciChart.Charting3D.Model;
using SciChart.Data.Extensions;
using SciChart.Examples.ExternalDependencies.Data;
namespace SciChart.Examples.Examples.Charts3D.CreateRealtime3DCharts
{
/// <summary>
/// Interaction logic for CreateRealTime3DPointCloudChart.xaml
/// </summary>
public partial class CreateRealTime3DPointCloudChart : UserControl
{
private XyzDataSeries3D<double> _xyzData;
private DispatcherTimer _timer;
private int _pointCount = 100000;
private readonly Random _random = new Random();
public CreateRealTime3DPointCloudChart()
{
InitializeComponent();
OnStart();
}
private void OnStart()
{
StartButton.IsChecked = true;
PauseButton.IsChecked = false;
ResetButton.IsChecked = false;
if (ScatterRenderableSeries3D.DataSeries == null)
{
_xyzData = new XyzDataSeries3D<double>();
// First load, fill with some random values
for (int i = 0; i < _pointCount; i++)
{
double x = DataManager.Instance.GetGaussianRandomNumber(50, 15);
double y = DataManager.Instance.GetGaussianRandomNumber(50, 15);
double z = DataManager.Instance.GetGaussianRandomNumber(50, 15);
_xyzData.Append(x, y, z);
}
ScatterRenderableSeries3D.DataSeries = _xyzData;
}
if (_timer == null)
{
_timer = new DispatcherTimer(DispatcherPriority.Render);
_timer.Interval = TimeSpan.FromMilliseconds(1);
_timer.Tick += OnTimerTick;
}
_timer.Start();
}
private void OnTimerTick(object sender, EventArgs e)
{
// Subsequent load, update point positions using a sort of brownian motion by using random
//
// Access Raw 'arrays' to the inner data series. This is the fastest way to read and access data, however
// any operations will not be thread safe, and will not trigger a redraw. This is why we invalidate below
//
// See also XyzDataSeries.Append, Update, Remove, Insert which are atomic operations
//
// Note that the count of raw arrays may be greater than _xyzData.Count
double[] xDataRaw = _xyzData.XValues.ToUncheckedList();
double[] yDataRaw = _xyzData.YValues.ToUncheckedList();
double[] zDataRaw = _xyzData.ZValues.ToUncheckedList();
// Update the data positions simulating 3D random walk / brownian motion
for (int i = 0, count = _xyzData.Count; i < count; i++)
{
xDataRaw[i] += _random.NextDouble() - 0.5;
yDataRaw[i] += _random.NextDouble() - 0.5;
zDataRaw[i] += _random.NextDouble() - 0.5;
}
// Raise DataSeriesChanged event and trigger chart updates
_xyzData.IsDirty = true;
_xyzData.OnDataSeriesChanged(DataSeriesUpdate.DataChanged, DataSeriesAction.Update);
}
private void OnPause()
{
_timer.Stop();
StartButton.IsChecked = false;
PauseButton.IsChecked = true;
ResetButton.IsChecked = false;
}
private void OnReset()
{
_timer.Stop();
StartButton.IsChecked = false;
PauseButton.IsChecked = false;
ResetButton.IsChecked = true;
using (sciChart.SuspendUpdates())
{
ScatterRenderableSeries3D.DataSeries = null;
sciChart.InvalidateElement();
ScatterRenderableSeries3D.GetSceneEntity().Update();
ScatterRenderableSeries3D.GetSceneEntity().RootSceneEntity.Update();
}
}
private void StartButton_Click(object sender, RoutedEventArgs e)
{
OnStart();
}
private void PauseButton_Click(object sender, RoutedEventArgs e)
{
OnPause();
}
private void ResetButton_Click(object sender, RoutedEventArgs e)
{
OnReset();
}
private void CreateRealTime3DPointCloudChart_OnUnloaded(object sender, RoutedEventArgs e)
{
if (_timer != null)
{
_timer.Stop();
_timer.Tick -= OnTimerTick;
_timer = null;
}
}
}
}