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 line chart with four series and multiple top / bottom X-Axis and left / right Y-Axis. SciChart supports multiple top or bottom X-Axes and multiple left and right Y-Axes. This example shows in a simple way how to register a line series on each axis.
Example Usage
– Drag any axis to scale.
– Drag the chart to zoom.
– Double click to reset zoom.
Documentation Links
The C#/WPF source code for the WPF Chart Multiple XAxis 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.ModifyAxisBehaviour.MultipleXAxes"
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"
Loaded="MultipleXAxes_Loaded"
d:DesignHeight="400"
d:DesignWidth="600"
mc:Ignorable="d">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<ext:SciChartInteractionToolbar TargetSurface="{Binding Source={x:Reference Name=sciChart}}">
<ext:FlyoutMenuButton Content="ZM"
Padding="0"
Style="{StaticResource FlyoutMenuButtonStyle}">
<ext:FlyoutMenuButton.PopupContent>
<StackPanel MinWidth="150" Orientation="Vertical">
<TextBlock Text="When Dragging to Zoom" />
<ext:FlyoutSeparator />
<CheckBox x:Name="zoomXAxisOnly"
Margin="4"
Content="Zoom X-Axis Only"
IsChecked="True"
ToolTipService.ToolTip="When checked, the zoom reticule expands vertically, and a zoom on the X-Axis is performed" />
</StackPanel>
</ext:FlyoutMenuButton.PopupContent>
</ext:FlyoutMenuButton>
</ext:SciChartInteractionToolbar>
<!-- Create the chart surface -->
<s:SciChartSurface Name="sciChart" Grid.Column="1">
<!-- Declare RenderableSeries and assign to Y-Axis -->
<s:SciChartSurface.RenderableSeries>
<s:FastLineRenderableSeries x:Name="redLine"
Stroke="#FFFF1919"
StrokeThickness="1"
XAxisId="BottomAxisId"
YAxisId="LeftAxisId" />
<s:FastLineRenderableSeries x:Name="greenLine"
Stroke="#FF279B27"
StrokeThickness="1"
XAxisId="BottomAxisId"
YAxisId="LeftAxisId" />
<s:FastLineRenderableSeries x:Name="yellowLine"
Stroke="#FFFC9C29"
StrokeThickness="1"
XAxisId="TopAxisId"
YAxisId="RightAxisId" />
<s:FastLineRenderableSeries x:Name="blueLine"
Stroke="#FF4083B7"
StrokeThickness="1"
XAxisId="TopAxisId"
YAxisId="RightAxisId" />
</s:SciChartSurface.RenderableSeries>
<!-- Create an X Axis -->
<s:SciChartSurface.XAxes>
<s:DateTimeAxis AxisAlignment="Bottom"
AxisTitle="Bottom Axis"
BorderBrush="#FFFF1919"
BorderThickness="0,1,0,0"
Id="BottomAxisId"
TickTextBrush="#FFFF1919" />
<s:DateTimeAxis AxisAlignment="Top"
AxisTitle="Top Axis"
BorderBrush="#FF279B27"
BorderThickness="0,0,0,1"
Id="TopAxisId"
TickTextBrush="#FF279B27" />
</s:SciChartSurface.XAxes>
<!-- Create Y Axes on the Left and Right. Optional bands give a cool look and feel for minimal performance impact -->
<s:SciChartSurface.YAxes>
<s:NumericAxis AxisAlignment="Left"
AxisTitle="Left Axis"
BorderBrush="#FFFC9C29"
BorderThickness="0,0,1,0"
DrawMajorBands="True"
GrowBy="0.05, 0.05"
Id="LeftAxisId"
TextFormatting="#.0"
TickTextBrush="#FFFC9C29" />
<s:NumericAxis AxisAlignment="Right"
AxisTitle="Right Axis"
BorderBrush="#FF4083B7"
BorderThickness="1,0,0,0"
GrowBy="0.05, 0.05"
Id="RightAxisId"
TextFormatting="#.0"
TickTextBrush="#FF4083B7" />
</s:SciChartSurface.YAxes>
<!-- Create chart modifiers to zoom, drag X,Y Axes and double click to zoom extents -->
<s:SciChartSurface.ChartModifier>
<s:ModifierGroup>
<s:RubberBandXyZoomModifier IsXAxisOnly="{Binding Source={x:Reference Name=zoomXAxisOnly}, Path=IsChecked, Mode=TwoWay}" />
<s:ZoomPanModifier ClipModeX="None" />
<s:XAxisDragModifier AxisId="TopAxisId" />
<s:XAxisDragModifier AxisId="BottomAxisId" />
<s:YAxisDragModifier AxisId="LeftAxisId" />
<s:YAxisDragModifier AxisId="RightAxisId" />
<s:LegendModifier Margin="10"
HorizontalAlignment="Center"
VerticalAlignment="Bottom"
GetLegendDataFor="AllSeries"
LegendPlacement="Inside"
Orientation="Horizontal"
ShowLegend="True" />
<s:ZoomExtentsModifier ExecuteOn="MouseDoubleClick" />
</s:ModifierGroup>
</s:SciChartSurface.ChartModifier>
</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
//
// MultipleXAxes.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 SciChart.Charting.Model.DataSeries;
namespace SciChart.Examples.Examples.ModifyAxisBehaviour
{
/// <summary>
/// Interaction logic for MultipleXAxes.xaml
/// </summary>
public partial class MultipleXAxes : UserControl
{
// Used to generate Random Walk
private Random _random = new Random(251916);
const int Count = 2000;
public MultipleXAxes()
{
InitializeComponent();
}
private void MultipleXAxes_Loaded(object sender, RoutedEventArgs e)
{
// Batch updates with one redraw
using (sciChart.SuspendUpdates())
{
// Add four data-series
var dataSeries0 = new XyDataSeries<DateTime, double>();
var dataSeries1 = new XyDataSeries<DateTime, double>();
var dataSeries2 = new XyDataSeries<DateTime, double>();
var dataSeries3 = new XyDataSeries<DateTime, double>();
// Fill each dataset with 2,000 pts of X,Y values (Date,Double)
// and ensure RenderableSeries has its datasource
redLine.DataSeries = FillData(dataSeries0, "Red Line");
greenLine.DataSeries = FillData(dataSeries1, "Green Line");
yellowLine.DataSeries = FillData(dataSeries2, "Orange Line");
blueLine.DataSeries = FillData(dataSeries3, "Blue Line");
}
sciChart.ZoomExtents();
}
private IDataSeries FillData(IXyDataSeries<DateTime, double> dataSeries, string name)
{
double randomWalk = 10.0;
var startDate = new DateTime(2012, 01, 01);
// Generate the X,Y data with sequential dates on the X-Axis and slightly positively biased random walk on the Y-Axis
var xBuffer = new DateTime[Count];
var yBuffer = new double[Count];
for (int i = 0; i < Count; i++)
{
randomWalk += (_random.NextDouble() - 0.498);
yBuffer[i] = randomWalk;
xBuffer[i] = startDate.AddMinutes(i * 10);
}
// Buffer above and append all in one go to avoid multiple recalculations of series range
dataSeries.Append(xBuffer, yBuffer);
dataSeries.SeriesName = name;
return dataSeries;
}
}
}