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 Tenor Curves example demonstrates how to combine 3D Charts and 2D Charts in the same example, in this case to display sample tenor curve data.
3D Charts are provided by the SciChart3DSurface Type. In this example we use a UniformGridDataSeries3D and a SurfaceMeshRenderableSeries3D to visualize the 3D surface. Rotation of the 3D chart is provided by the OrbitModifier3D.
2D Line Charts are provided by the SciChartSurface. This uses a single FastLineRenderableSeries and XyDataSeries type to display line data, with an optional PointMarker.
Documentation Links
– SciChart3DSurface Type
– SciChartSurface Type
– SurfaceMeshRenderableSeries3D
– UniformGridDataSeries3D
The C#/WPF source code for the WPF 3D Chart Tenor Curves Plot 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.SeeFeaturedApplication.TenorCurves3DChart.TenorCurves3DChart"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:ext="http://schemas.abtsoftware.co.uk/scichart/exampleExternals"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:s="http://schemas.abtsoftware.co.uk/scichart"
xmlns:s3D="http://schemas.abtsoftware.co.uk/scichart3D"
d:DesignHeight="400"
d:DesignWidth="600"
mc:Ignorable="d">
<UserControl.Resources>
<s3D:GradientColorPalette x:Key="HeightColorMap"
ContourStrokeThickness="1.0">
<s3D:GradientColorPalette.GradientStops>
<GradientStop Offset="1.0" Color="DarkRed" />
<GradientStop Offset="0.9" Color="Red" />
<GradientStop Offset="0.7" Color="Yellow" />
<GradientStop Offset="0.5" Color="GreenYellow" />
<GradientStop Offset="0.3" Color="Cyan" />
<GradientStop Offset="0.1" Color="Blue" />
<GradientStop Offset="0.0" Color="#1D2C6B" />
</s3D:GradientColorPalette.GradientStops>
</s3D:GradientColorPalette>
<LinearGradientBrush x:Key="MountainChartFill" StartPoint="0,0" EndPoint="0,1">
<LinearGradientBrush.GradientStops>
<GradientStop Offset="0" Color="#4682B4"/>
<GradientStop Offset="1" Color="#374682B4"/>
</LinearGradientBrush.GradientStops>
</LinearGradientBrush>
</UserControl.Resources>
<Grid Background="#FF1C1C1E">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="2.5*" />
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<!-- The SciChart3DInteractionToolbar adds rotate, orbit, zoom, pan, zoom extents functionality -->
<!-- to the chart and is included for example purposes. -->
<!-- If you wish to know how to zoom and pan a 3D chart then do a search for Zoom Pan in the Examples suite! -->
<ext:SciChart3DInteractionToolbar Grid.RowSpan="2" TargetSurface="{Binding Source={x:Reference Name=sciChart}}" />
<s3D:SciChart3DSurface x:Name="sciChart"
Grid.Row="0"
Grid.RowSpan="2"
Grid.Column="1"
BorderThickness="0"
WorldDimensions="200,200,200"
IsFpsCounterVisible="False">
<s3D:SciChart3DSurface.Camera>
<s3D:Camera3D Position="-225,300,-225" Target="0,50,0" />
</s3D:SciChart3DSurface.Camera>
<s3D:SciChart3DSurface.RenderableSeries>
<s3D:SurfaceMeshRenderableSeries3D x:Name="surfaceMeshRenderableSeries"
DrawSkirt="False"
MeshColorPalette="{StaticResource HeightColorMap}"
MeshPaletteMode="HeightMapInterpolated"
Stroke="#4682B4"
StrokeThickness="1.0"/>
</s3D:SciChart3DSurface.RenderableSeries>
<s3D:SciChart3DSurface.XAxis>
<s3D:NumericAxis3D x:Name="XAx3D" VisibleRange="0,10" AxisTitle="Tenor" AxisTitleOffset="60"/>
</s3D:SciChart3DSurface.XAxis>
<s3D:SciChart3DSurface.YAxis>
<s3D:NumericAxis3D x:Name="YAx3D"
AxisTitle="Rate (%)"
AxisTitleOffset="60"
TextFormatting="#"
VisibleRange="0,10" />
</s3D:SciChart3DSurface.YAxis>
<s3D:SciChart3DSurface.ZAxis>
<s3D:DateTimeAxis3D x:Name="ZAx3D" DrawMajorBands="True" AxisTitle="Date" AxisTitleOffset="100"/>
</s3D:SciChart3DSurface.ZAxis>
<s3D:SciChart3DSurface.ChartModifier>
<s3D:ModifierGroup3D>
<s3D:MouseWheelZoomModifier3D/>
<s3D:TooltipModifier3D />
</s3D:ModifierGroup3D>
</s3D:SciChart3DSurface.ChartModifier>
</s3D:SciChart3DSurface>
<s:HeatmapColorMap Grid.Row="0"
Grid.RowSpan="2"
Grid.Column="1"
Margin="15"
HorizontalAlignment="Right"
VerticalAlignment="Stretch"
Background="{Binding Source={x:Reference Name=sciChart}, Path=Background}"
BorderBrush="#777"
BorderThickness="1"
Foreground="{Binding Source={x:Reference Name=sciChart}, Path=Foreground}"
Maximum="{Binding Source={x:Reference Name=surfaceMeshRenderableSeries}, Path=Maximum}"
Minimum="{Binding Source={x:Reference Name=surfaceMeshRenderableSeries}, Path=Minimum}"
Opacity="0.8"
Orientation="Vertical"
TextFormatting="0.00">
<s:HeatmapColorMap.ColorMap>
<LinearGradientBrush>
<GradientStop Offset="1" Color="DarkRed" />
<GradientStop Offset="0.9" Color="Red" />
<GradientStop Offset="0.7" Color="Yellow" />
<GradientStop Offset="0.5" Color="GreenYellow" />
<GradientStop Offset="0.3" Color="Cyan" />
<GradientStop Offset="0.1" Color="Blue" />
<GradientStop Offset="0.0" Color="#1D2C6B" />
</LinearGradientBrush>
</s:HeatmapColorMap.ColorMap>
</s:HeatmapColorMap>
<s:SciChartSurface x:Name="sciChart2"
Grid.Row="0"
Grid.Column="2"
Margin="5">
<s:SciChartSurface.RenderableSeries>
<s:FastMountainRenderableSeries x:Name="MountainSeries0" Stroke="#4682b4"
StrokeThickness="5"
Fill="{StaticResource MountainChartFill}">
</s:FastMountainRenderableSeries>
<s:XyScatterRenderableSeries x:Name="ScatterSeries0">
<s:EllipsePointMarker Width="7" Height="7" Stroke="#366294" Fill="White" />
</s:XyScatterRenderableSeries>
</s:SciChartSurface.RenderableSeries>
<s:SciChartSurface.XAxis>
<s:NumericAxis DrawMajorGridLines="False"
DrawMinorGridLines="False"
DrawMajorBands="True"/>
</s:SciChartSurface.XAxis>
<s:SciChartSurface.YAxis>
<s:NumericAxis GrowBy="0,0.1" MaxAutoTicks="5"
DrawMajorGridLines="True"
DrawMinorGridLines="False"
DrawMajorBands="False"/>
</s:SciChartSurface.YAxis>
</s:SciChartSurface>
<s:SciChartSurface x:Name="sciChart3"
Grid.Row="1"
Grid.Column="2"
Margin="5">
<s:SciChartSurface.RenderableSeries>
<s:FastMountainRenderableSeries x:Name="MountainSeries1" Stroke="#4682b4"
StrokeThickness="5"
Fill="{StaticResource MountainChartFill}"
/>
<s:XyScatterRenderableSeries x:Name="ScatterSeries1">
<s:EllipsePointMarker Width="7" Height="7" Stroke="#366294" Fill="White" />
</s:XyScatterRenderableSeries>
</s:SciChartSurface.RenderableSeries>
<s:SciChartSurface.XAxis>
<s:NumericAxis DrawMajorGridLines="False"
DrawMinorGridLines="False"
DrawMajorBands="True"/>
</s:SciChartSurface.XAxis>
<s:SciChartSurface.YAxis>
<s:NumericAxis GrowBy="0,0.1" MaxAutoTicks="5"
DrawMajorGridLines="True"
DrawMinorGridLines="False"
DrawMajorBands="False"/>
</s:SciChartSurface.YAxis>
</s:SciChartSurface>
</Grid>
</UserControl>
// *************************************************************************************
// SCICHART® Copyright SciChart Ltd. 2011-2022. All rights reserved.
//
// Web: http://www.scichart.com
// Support: support@scichart.com
// Sales: sales@scichart.com
//
// TenorCurves3DChart.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.Controls;
using SciChart.Charting.Model.DataSeries;
using SciChart.Charting.Model.Filters;
using SciChart.Charting3D.Model;
using SciChart.Core.Extensions;
namespace SciChart.Examples.Examples.SeeFeaturedApplication.TenorCurves3DChart
{
/// <summary>
/// Interaction logic for TenorCurves3DChart.xaml
/// </summary>
public partial class TenorCurves3DChart : UserControl
{
public TenorCurves3DChart()
{
InitializeComponent();
var random = new Random();
int xSize = 25;
int zSize = 25;
var meshDataSeries = new UniformGridDataSeries3D<double,double,DateTime>(xSize, zSize);
var lineDataSeries = new XyDataSeries<double>();
var mountainDataSeries = new XyDataSeries<double, double>();
meshDataSeries.SeriesName = "Tenor Curves";
meshDataSeries.StartZ = new DateTime(2010,1,1);
meshDataSeries.StepZ = new TimeSpan(1,0,0,0).ToDateTime();
double step;
for (int x = 0; x < xSize; x++)
{
switch (x)
{
case 5: case 10:
step = 0.309;
break;
case 4: case 9:
step = 0.303;
break;
case 6: case 11:
step = 0.303;
break;
case 23:
step = 0.291;
break;
case 22:
step = 0.294;
break;
case 24:
step = 0.295;
break;
default:
step = 0.3;
break;
}
for (int z = 0; z < zSize; z++)
{
// Compute a slope function with some noise
var y = (z != 0) ? Math.Pow(z + random.NextDouble(), step) : Math.Pow((double)z + 1, 0.3);
// Compute a 3d parabola function
var nX = x - xSize / 2;
var nZ = z - zSize / 2;
var parabola = (nX * nX) + (nZ * nZ);
// Set the data
meshDataSeries[z, x] = y * (parabola + 50) * 0.1;
}
}
double average;
for (int x = 0; x < xSize; x++)
{
average = 0;
for (int z = 0; z < zSize; z++)
{
average += meshDataSeries[x, z];
}
lineDataSeries.Append(x, average / 25);
mountainDataSeries.Append(x, meshDataSeries[12, x]);
}
surfaceMeshRenderableSeries.DataSeries = meshDataSeries;
MountainSeries0.DataSeries = lineDataSeries.ToSpline(10);
ScatterSeries0.DataSeries = lineDataSeries;
MountainSeries1.DataSeries = mountainDataSeries.ToSpline(10);
ScatterSeries1.DataSeries = mountainDataSeries;
surfaceMeshRenderableSeries.Maximum = (double)meshDataSeries.YRange.Max;
surfaceMeshRenderableSeries.Minimum = (double)meshDataSeries.YRange.Min;
}
}
}