Pre loader

Adding Vertical slice with a DateTime XAxis issue: "A first chance exception of type 'System.NullReferenceException' occurred in Abt.Controls.SciChart.Wpf.dll"

Welcome to the SciChart Forums!

  • Please read our Question Asking Guidelines for how to format a good question
  • Some reputation is required to post answers. Get up-voted to avoid the spam filter!
  • We welcome community answers and upvotes. Every Q&A improves SciChart for everyone

WPF Forums | JavaScript Forums | Android Forums | iOS Forums

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

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

Please first to submit.

Try SciChart Today

Start a trial and discover why we are the choice
of demanding developers worldwide

Start TrialCase Studies