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.
Demonstrates a multi-series chart using the FastCandlestickRenderableSeries with three FastLineRenderableSeries showing the moving average of the closing price.
The example uses the CategoryDateTimeAxis which collapses overnight and weekend gaps in data, but, uses the Index to the data to calculate X-position. This means that all DataSeries must have the same number of data-points (you can pad DataSeries using double.NaN for null or empty points).
Example Usage
– ZoomPan, left-mouse drag to pan the chart
– Mousewheel, roll the mousewheel to zoom
– ZoomExtents, double click to zoom to extents
Tip! To get the effect of hiding the line for the first N points of a moving average, you can insert double.NaN into the XyDataSeries. double.NaN can be used to render gaps or continuous lines.
Documentation Links
– FastCandlestickRenderableSeries Type
– OhlcDataSeries Type
– CategoryDateTimeAxis vs. NumericAxis
– RenderableSeries API
The C#/WPF source code for the WPF Candlestick Chart 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.CreateSimpleChart.CandlestickChartExampleView"
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"
xmlns:ext="http://schemas.abtsoftware.co.uk/scichart/exampleExternals"
Loaded="CandlestickChartExampleView_OnLoaded"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
d:DesignHeight="400"
d:DesignWidth="600"
mc:Ignorable="d">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<!-- The SciChartInteractionToolbar adds zoom, pan, zoom extents and rotate functionality -->
<!-- to the chart and is included for example purposes. -->
<!-- If you wish to know how to zoom and pan a chart then do a search for Zoom Pan in the Examples suite! -->
<ext:SciChartInteractionToolbar TargetSurface="{Binding Source={x:Reference Name=sciChart}}" />
<!-- Create the chart surface -->
<s:SciChartSurface Name="sciChart" Grid.Column="1"
Padding="0"
BorderThickness="0">
<!-- Declare RenderableSeries -->
<s:SciChartSurface.RenderableSeries>
<!-- Candlestick bodies now support gradients as well as solid colours -->
<s:FastCandlestickRenderableSeries x:Name="candlestickSeries">
<s:FastCandlestickRenderableSeries.FillUp>
<LinearGradientBrush StartPoint="0,0" EndPoint="0,1">
<GradientStop Offset="0" Color="#55002200" />
<GradientStop Offset="1" Color="#FF00AA00" />
</LinearGradientBrush>
</s:FastCandlestickRenderableSeries.FillUp>
<s:FastCandlestickRenderableSeries.FillDown>
<LinearGradientBrush StartPoint="0,0" EndPoint="0,1">
<GradientStop Offset="0" Color="#55441111" />
<GradientStop Offset="1" Color="#FFFF0000" />
</LinearGradientBrush>
</s:FastCandlestickRenderableSeries.FillDown>
<s:FastCandlestickRenderableSeries.SeriesAnimation>
<s:SweepAnimation AnimationDelay="0:0:1" Duration="0:0:4"/>
</s:FastCandlestickRenderableSeries.SeriesAnimation>
</s:FastCandlestickRenderableSeries>
</s:SciChartSurface.RenderableSeries>
<!-- Create an X Axis -->
<s:SciChartSurface.XAxis>
<s:CategoryDateTimeAxis DrawMajorBands="True" />
</s:SciChartSurface.XAxis>
<!-- Create a Y Axis with GrowBy -->
<s:SciChartSurface.YAxis>
<s:NumericAxis GrowBy="0.1, 0.1" DrawMajorBands="True" />
</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
//
// CandlestickChartExampleView.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.Media.Animation;
using SciChart.Charting.Model.DataSeries;
using SciChart.Charting.Visuals.RenderableSeries.Animations;
using SciChart.Examples.ExternalDependencies.Common;
using SciChart.Examples.ExternalDependencies.Data;
namespace SciChart.Examples.Examples.CreateSimpleChart
{
public partial class CandlestickChartExampleView : UserControl
{
public CandlestickChartExampleView()
{
InitializeComponent();
}
private void CandlestickChartExampleView_OnLoaded(object sender, RoutedEventArgs e)
{
// Create a dataset of type x=DateTime, y=Double
var dataSeries = new OhlcDataSeries<DateTime, double>();
// Prices are in the format Time, Open, High, Low, Close (all IList)
var prices = DataManager.Instance.GetPriceData(Instrument.Indu.Value, TimeFrame.Daily);
// Append data to series. SciChart automatically redraws
dataSeries.Append(
prices.TimeData,
prices.OpenData,
prices.HighData,
prices.LowData,
prices.CloseData);
sciChart.RenderableSeries[0].DataSeries = dataSeries;
// Zoom Extents - necessary as we have AutoRange=False
sciChart.ZoomExtents();
}
}
}