I am sending the code with an error.
MainWindow.xaml
<Window x:Class="TeeChart.MainWindow"
xmlns="
http://schemas.microsoft.com/winfx/2006 ... esentation"
xmlns:x="
http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="
http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="
http://schemas.openxmlformats.org/marku ... ility/2006"
xmlns:local="clr-namespace:TeeChart"
xmlns:wpf="clr-namespace:Steema.TeeChart.WPF;assembly=TeeChart.WPF"
mc:Ignorable="d"
Title="MainWindow" Height="500" Width="800">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<wpf:TChart Name="tChart" Grid.Row="0"/>
<StackPanel Orientation="Horizontal" Grid.Row="1" HorizontalAlignment="Center">
<Button x:Name="BtnGetImage" Click="BtnGetImage_OnClick" Margin="5">Save chart to memory stream</Button>
</StackPanel>
</Grid>
</Window>
MainWindow.xaml.cs
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
this.Loaded += MainWindow_Loaded;
}
private void MainWindow_Loaded(object sender, RoutedEventArgs e)
{
tChart.Series.Clear();
tChart.Axes.Custom.Clear();
tChart.Width = 731;
tChart.Height = 448;
tChart.Axes.Bottom.SetMinMax(0, 12);
AddFirstTwoSeries();
var mySeries = SetMySeries();
SetDataMySeries(mySeries);
AddCustomAxes(mySeries);
}
private void AddCustomAxes(Series mySeries)
{
Steema.TeeChart.WPF.Axis newAxis = new Steema.TeeChart.WPF.Axis();
newAxis.Horizontal = false;
Steema.TeeChart.WPF.Axis customAxis = tChart.Axes.Custom.Add(newAxis);
mySeries.CustomVertAxis = customAxis;
var customAxisId = tChart.Axes.Custom.IndexOf(customAxis);
var myCustomAxis = tChart.Axes.Custom[customAxisId];
myCustomAxis.Visible = true;
myCustomAxis.AxisPen.Color = mySeries.Color;
myCustomAxis.MinorGrid.Visible = false;
myCustomAxis.Labels.Font.Color = mySeries.Color;
myCustomAxis.Labels.Font.Bold = false; //True
myCustomAxis.Ticks.Visible = false;
myCustomAxis.MinorTicks.Visible = false;
myCustomAxis.MinorGrid.Visible = false;
myCustomAxis.Grid.Visible = false;
myCustomAxis.AxisPen.Visible = false;
myCustomAxis.Increment = 1;
myCustomAxis.Labels.ValueFormat = "###0.###";
myCustomAxis.Automatic = false;
myCustomAxis.Maximum = (double) 10;
myCustomAxis.Minimum = (double) 0;
myCustomAxis.PositionUnits = Steema.TeeChart.WPF.PositionUnits.Percent;
myCustomAxis.RelativePosition = 0;
}
private static void SetDataMySeries(Series mySeries)
{
mySeries.Title = "Di";
mySeries.Legend.Visible = true;
mySeries.Add(2, (double)2, " 1", Colors.Blue);
mySeries.Add(3, (double)12, " 2", Colors.Blue);
}
private Series SetMySeries()
{
Steema.TeeChart.WPF.Styles.Series series3 = tChart.Series.Add(new Steema.TeeChart.WPF.Styles.Line(tChart.Chart));
var seriesIndex = tChart.Series.IndexOf(series3);
var mySeries = tChart.Series[seriesIndex];
((Steema.TeeChart.WPF.Styles.Line) mySeries).Pointer.Style =
(Steema.TeeChart.WPF.Styles.PointerStyles) 0;
((Steema.TeeChart.WPF.Styles.Line) mySeries).Pointer.Visible = true;
((Steema.TeeChart.WPF.Styles.Line) mySeries).LinePen.Visible = false;
return mySeries;
}
private void AddFirstTwoSeries()
{
tChart.Series.Add(new Steema.TeeChart.WPF.Styles.Line(tChart.Chart));
tChart.Series[0].VertAxis = Steema.TeeChart.WPF.Styles.VerticalAxis.Left;
tChart.Series[0].Legend.Visible = false;
tChart.Series.Add(new Steema.TeeChart.WPF.Styles.Line(tChart.Chart));
tChart.Series[1].VertAxis = Steema.TeeChart.WPF.Styles.VerticalAxis.Right;
tChart.Series[1].Legend.Visible = false;
}
private void BtnGetImage_OnClick(object sender, RoutedEventArgs e)
{
var xamlFormat = new XAMLFormat(tChart.Chart);
using (MemoryStream ms = new MemoryStream())
{
try
{
xamlFormat.Save(ms);
MessageBox.Show("Ok", "Saving chart to memory stream");
}
catch (Exception ex)
{
Console.WriteLine(ex);
MessageBox.Show($" {ex.Message}", "Error when saving chart to memory stream ");
}
}
}
}