SciChart® the market leader in Fast WPF Charts, WPF 3D Charts, and now iOS Charting & Android Chart Components

Welcome to the SciChart Community Forums!

Please use the forums below to ask questions about SciChart. Take a moment to read our Question asking guidelines on how to ask a good question and our support policy

We also have a tag=SciChart on Stackoverflow.com where you can earn rep for your questions!

Answered
0
0

Hello, SciChart team, i’m trying to implement vertical slices on my chart surface, but X axis is a DateTimeAxis, but i’m getting nullReferenceException when trying to move (just click on it).

“System.NullReferenceException occurred
_HResult=-2147467261
_message=Ссылка на объект не указывает на экземпляр объекта.
HResult=-2147467261
IsTransient=false
Message=Ссылка на объект не указывает на экземпляр объекта.
Source=Abt.Controls.SciChart.Wpf
StackTrace:
в Abt.Controls.SciChart.Visuals.Annotations.AnnotationBase.GetBasePoints()
InnerException: “

trying to solve this problem i downloaded scischart 3.42 but this didn’t help, it even made things worse underlining my scichartsurface declaration in .xaml file saying “2 is not a valid value for property orintation”
which is not used, and this chart worked before upgrade.
please help me out,
Volkov Alexander

Update: full rebuilding solved the latter problem. i’m adding zip containing txt with scichartsurface definition and methods from .cs which add and remove slices

  • You must to post comments
Great Answer
1
0

Hi Alexander,

I took a look on your code and noticed that your YAxis definition has custom Id :

 sciChart.YAxes.Add(new Abt.Controls.SciChart.Visuals.Axes.NumericAxis()
        {
            AxisTitle = "test",
            AutoRange = Abt.Controls.SciChart.Visuals.Axes.AutoRange.Once,
            Id = "131"
        });

And your VerticalLineAnnotation definition doesn’t have the same YAxisId value. To fix your code sample you need to define your annotation next way:

 this.sciChart.Annotations.Add(new VerticalLineAnnotation()
        {
            X1 = DateTime.Today,
            Style = (Style) Resources["sliceStyle"],
            YAxisId = "131"
        });

This happens because VerticalLineAnnotation requires both XAxis and YAxis because it supports different VerticalAlignment values and YAxis is used to place it according to this value. So to prevent this NullReferenceException you just need to ensure that your VerticalLineAnnotations have appropriate XAxisId and YAxisId values.

Hope it helps!

  • Alexander Volkov
    Hello, Yura, this really helped. So I create from 1 to 5 Axes and assign slice's yaxisid: "YAxisId = SciChartSurface.YAxes[0].Id" . This pretty much works except when I want to allow user to add slices and pan is turned on, then slices appear on double click but not on first click.
  • You must to post comments
1
0

Hello, Andrew, after 10 minutes of trying to hang this simple code i recalled that i create YAxes programmatically, so i deleted YAxis from xaml and created one with code, and the error occurred again.
here’s the code for xaml:

<Window x:Class="TikReportTool.ReportTest"
        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"
        Title="MainWindow" Height="350" Width="525">
    <Window.Resources>
        <Style x:Key="sliceStyle" TargetType="s:VerticalLineAnnotation">
            <Setter Property= "ShowLabel"    Value="True"   />
            <Setter Property="IsEditable"   Value="True"    />
            <Setter Property="Stroke" Value="#427EF6" />
            <Setter Property="LabelPlacement" Value="Axis"  />
        </Style>
    </Window.Resources>
        <Grid>
        <s:SciChartSurface x:Name="sciChart" HorizontalAlignment="Stretch" Margin="0" MinHeight="300" VerticalAlignment="Stretch" Grid.Row="2" s:ThemeManager.Theme="Chrome" >
            <s:SciChartSurface.XAxis>
                <s:DateTimeAxis/>
            </s:SciChartSurface.XAxis>
        </s:SciChartSurface>
        </Grid>
</Window>

and for CS:

public partial class ReportTest : Window
    {
        public ReportTest()
        {
            InitializeComponent();

            sciChart.YAxes.Add(new Abt.Controls.SciChart.Visuals.Axes.NumericAxis() { AxisTitle = "test", AutoRange = Abt.Controls.SciChart.Visuals.Axes.AutoRange.Once, Id = "131" });
            this.sciChart.XAxis.VisibleRange = new DateRange(DateTime.Today.AddDays(-30), DateTime.Today.AddDays(30));
            this.sciChart.Annotations.Add(new VerticalLineAnnotation()
            {
                X1 = DateTime.Today,
                Style = (Style)Resources["sliceStyle"]
            });
        }
    }
  • You must to post comments
0
0

Hi Alexander,

After our discussions, I have to confess I’m having trouble reproducing this issue. Here is the code I’ve tried:

XAML

<Window x:Class="WpfApplication43.MainWindow"
        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"
        Title="MainWindow" Height="350" Width="525">
    <Grid>
        <s:SciChartSurface x:Name="sciChart">
            <s:SciChartSurface.XAxis>
                <s:DateTimeAxis/>
            </s:SciChartSurface.XAxis>

            <s:SciChartSurface.YAxis>
                <s:NumericAxis/>
            </s:SciChartSurface.YAxis>   

        </s:SciChartSurface>
    </Grid>
</Window>

Code-behind

using System;
using System.Windows;
using Abt.Controls.SciChart;
using Abt.Controls.SciChart.Visuals.Annotations;

namespace WpfApplication43
{
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();

            this.sciChart.XAxis.VisibleRange = new DateRange(DateTime.Today.AddDays(-30), DateTime.Today.AddDays(30));
            this.sciChart.Annotations.Add(new VerticalLineAnnotation()
            {
                X1 = DateTime.Today, 
                ShowLabel = true
            });
        }
    }
}

Result:

(attached image)

Can you modify the code until the error occurs?

Best regards,
Andrew

Images
  • You must to post comments
Showing 3 results
Your Answer

Please first to submit.