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!

Please note: SciChart team will only answer questions from customers with active support subscriptions. Expired support questions will be ignored. If your support status shows incorrectly, contact us and we will be glad to help.

0
0

Hi,

I’m using SciChartGroup with SciChartSurface to create a chart with multiple panes, each pane has a set of cursors including the CursorModifier with ShowAxisLabels=”True”. When mouse is over the panel where no any series I get an error:

Object reference not set to an instance of an object.

at Abt.Controls.SciChart.Visuals.Axes.TradeChartAxisLabelFormatter.c94f1c4a8b3176ab34988be02ae5c9853(IComparable cd9eb4abc8062a13034d7e1a95015cf34, Boolean c202464bb46bef74e568ab9e85eabcfae)
at Abt.Controls.SciChart.Visuals.Axes.TradeChartAxisLabelFormatter.FormatLabel(IComparable dataValue)
at Abt.Controls.SciChart.Visuals.Axes.AxisBase.FormatText(IComparable value, String format)
at Abt.Controls.SciChart.Visuals.Axes.AxisBase.HitTest(Point atPoint)
at Abt.Controls.SciChart.ChartModifiers.InspectSeriesModifierBase.HitTestAxis(IAxis axis, Point atPoint)
at Abt.Controls.SciChart.ChartModifiers.CursorModifier.c987c837b119aed1f35c1f0ac2cd58b4b.cf244cc494090613db790079d45f87bd9(IAxis c9602bd29fd5d7a98bc0428c28ceb8250)
at System.Linq.Enumerable.WhereSelectEnumerableIterator2.MoveNext()
at System.Linq.Enumerable.FirstOrDefault[TSource](IEnumerable
1 source)
at Abt.Controls.SciChart.ChartModifiers.CursorModifier.GetAxesData(Point mousePoint)
at Abt.Controls.SciChart.ChartModifiers.CursorModifier.HandleMasterMouseMove(Point mousePoint)
at Abt.Controls.SciChart.ChartModifiers.InspectSeriesModifierBase.cf02abbb1e36d2956f3f92f4d796607cf(Point cfe7da3d2fb2c1ba75ba1814199d02354)
at Abt.Controls.SciChart.ChartModifiers.InspectSeriesModifierBase.HandleMouseEvent(Point mousePoint, Boolean isMaster)
at Abt.Controls.SciChart.ChartModifiers.InspectSeriesModifierBase.OnModifierMouseMove(ModifierMouseArgs e)
at Abt.Controls.SciChart.ChartModifiers.ModifierGroup.c07d1dcb1c7ba461bbcbf5a1dd47c58a5(IChartModifier c6b1effd112e5355cd5f051dd91cd4f67, ModifierMouseArgs cbb39038dde40bfc3fdcfa70f4bbf8778)
at Abt.Controls.SciChart.ChartModifiers.ModifierGroup.c9e8960a6a8527c20ac9e46e162c72b22(Action2 c4bd4ab823835cf92d221476b6fb65a17, ModifierMouseArgs c4c23d80d4d060e409c3479ef17d6c65e)
at Abt.Controls.SciChart.ChartModifiers.ModifierGroup.OnModifierMouseMove(ModifierMouseArgs e)
at Abt.Controls.SciChart.Utility.Mouse.MouseManager.ca5839647cb861fa726b3261de72c52c0(ModifierMouseArgs cbb39038dde40bfc3fdcfa70f4bbf8778, IReceiveMouseEvents c18509698be3f9366c690e7d2b107b62c, Boolean c3791a1b71c1577bde30b55c12b2a5583)
at Abt.Controls.SciChart.Utility.Mouse.MouseManager.cf88844ca415efe316ebbc6460c4d5477.c7ca7af35639f570327394b11001b543a.c5980502f76d6e282773f80c5da0f84e7(IReceiveMouseEvents c133657388cc0f6f6615e21e129ac4b3a)
at A.c19dd4d74f6373c95c517d29624d76e4b.cacf72b657252e3e73860afb89d70cb9f[c13c28af86f0b14202b9c7ef43b1bd11a](IEnumerable
1 c40a30a1bb6416cd164565919fdef15a9, Action`1 c885aac61bc9832561b7ff07903c88d5e)
at Abt.Controls.SciChart.Utility.Mouse.MouseManager.cf88844ca415efe316ebbc6460c4d5477.c6b7aec04ebfc28e092adf0e569761d15(Object cae49ecc8585f35e8dd5ce624f7fb7ab5, MouseEventArgs c4c23d80d4d060e409c3479ef17d6c65e)
at A.cd43732d305fa7b65b611005fdcef35d8.c769264f2530d8b47196e47cbbe58cb89(MouseEventArgs cbb39038dde40bfc3fdcfa70f4bbf8778)
at A.cd43732d305fa7b65b611005fdcef35d8.cbe8969038b3b47585f72b9c703cd47da(Object c5e18ac7ef25e3e9c51dc36756b25ed1e, MouseEventArgs c4c23d80d4d060e409c3479ef17d6c65e)
at System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)
at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
at System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)
at System.Windows.UIElement.RaiseTrustedEvent(RoutedEventArgs args)
at System.Windows.Input.InputManager.ProcessStagingArea()
at System.Windows.Input.InputProviderSite.ReportInput(InputReport inputReport)
at System.Windows.Interop.HwndMouseInputProvider.ReportInput(IntPtr hwnd, InputMode mode, Int32 timestamp, RawMouseActions actions, Int32 x, Int32 y, Int32 wheel)
at System.Windows.Interop.HwndMouseInputProvider.FilterMessage(IntPtr hwnd, WindowMessage msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
at System.Windows.Interop.HwndSource.InputFilterMessage(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)
at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)
at System.Windows.Threading.Dispatcher.LegacyInvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Int32 numArgs)
at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)
at MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG& msg)
at System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame)
at System.Windows.Application.RunInternal(Window window)
at System.Windows.Application.Run()
at SciTest.App.Main() in d:\Projects\Test\SciChart\SciTest – копия\SciTest\obj\Debug\App.g.cs:line 0
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()

I attached a sample project.

Attachments
  • You must to post comments
0
0

Hi Esper,

We will investigate further. To resolve this by workaround, you can try this:

    /// <summary>
    /// LabelFormatters are used to format cursor and axis labels from DataValues
    /// The DataValue will be an Integer index in the case of CategoryDateTimeAxis
    /// The DataValue will be a Double in the case of NumericAxis and a Double for DateTimeAxis
    /// For DateTimeAxis convert the Double to DateTIme like this: new DateTime((long)dataValue)
    /// </summary>
    public class CustomTradeChartAxisLabelFormatter : TradeChartAxisLabelFormatter
    {
        public override string FormatCursorLabel(IComparable dataValue)
        {
            if (dataValue == null) return "N/A";
            return base.FormatCursorLabel(dataValue);
        }

        public override string FormatLabel(IComparable dataValue)
        {
            if (dataValue == null) return "N/A";
            return base.FormatLabel(dataValue);
        }
    }

Create a custom LabelFormatter above that avoids the exception.

Then, use it like this

C#

    // Assumes XAxis is a CategoryDateTimeAxis
    sciChartSurface.XAxis.LabelFormatter = new CustomTradeChartAxisLabelFormatter();

or XAML

<!-- Assumes you have declared CustomTradeChartAxisLabelFormatter as a resource in your UserControl.Resources -->
<s:CategoryDateTimeAxis LabelFormatter="{StaticResource CustomTradeChartAxisLabelFormatter}"/>

Best regards,
Andrew

  • esper
    Hi,Thanks, it solved the problem for me.
  • Ian Carson
    Hi GuysThis workaround does not seem to be effective when the chart surface is in a datatemplate. My DataTemplate looks like this[code title="ChartTemplate"] [/code]And I am using the CustomFormatter as described above.What happens is I get a dataValue of "1/01/0001 12:00AM" which is not null and then the base.FormatLabel(dataValue) call falls over with an "Object not set..." error
  • Ian Carson
    Sorry not used to your code tags. Here's the DataTemplate as text
  • You must to post comments
0
0

Now I really feel like a noob 😳

        <DataTemplate x:Key="ChartTemplate">
            <Grid Margin="0"
                  HorizontalAlignment="Stretch"
                  VerticalAlignment="Stretch"
                  MinHeight="400">
                <Grid.RowDefinitions>
                    <RowDefinition Height="3*" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="*" />
                </Grid.RowDefinitions>
                <visuals:SciStockChart Grid.Row="0"
                                       Margin="0"
                                       x:Name="PriceChart"
                                       BarTimeFrame="-1"
                                       SeriesSource="{Binding Path=PriceChartAndOverlaySeries}"
                                       visuals:ThemeManager.Theme="BlackSteel"
                                       DrawMinorGridLines="False"
                                       DrawMajorGridLines="True"
                                       MinorsPerMajor="5"
                                       XAxisTextFormatting="dd MMM yyyy"
                                       YAxisTextFormatting="0.00">
                    <visuals:SciChartSurface.XAxis>
                        <visuals:CategoryDateTimeAxis DrawMajorBands="True"
                                                GrowBy="0.0, 0.1" LabelFormatter="{StaticResource CustomTradeChartAxisLabelFormatter}" />
                    </visuals:SciChartSurface.XAxis>
                </visuals:SciStockChart>
                <uiServices:CollapsableGridSplitter Grid.Row="1"
                                                    Height="10"
                                                    HorizontalAlignment="Stretch"
                                                    VerticalAlignment="Center"
                                                    CollapseMode="Next"
                                                    IsCollapsed="False"
                                                    IsTabStop="False" />
                <ItemsControl x:Name="IndicatorsContainer"
                              Grid.Row="2"
                              Margin="0"
                              Background="Aqua"
                              ItemsSource="{Binding Indicators}"
                              ItemTemplate="{StaticResource IndicatorTemplate}">
                    <ItemsControl.ItemsPanel>
                        <ItemsPanelTemplate>
                            <UniformGrid Columns="1"
                                         Background="Bisque" />
                        </ItemsPanelTemplate>
                    </ItemsControl.ItemsPanel>
                </ItemsControl>
            </Grid>
        </DataTemplate>

  • You must to post comments
0
0

Hi Guys

I solved this one with a slight change to the CustomTradeChartAxisLabelFormatter in a post on this forum.

Here is the code for anyone who might find it useful.

Regards
Ian Carson

    public class CustomTradeChartAxisLabelFormatter : TradeChartAxisLabelFormatter
    {
        public override string FormatCursorLabel(IComparable dataValue)
        {
            if (dataValue == null)
            {
                return "N/A";
            }

            var date = Convert.ToDateTime(dataValue);

            if (date.Year == 1)
            {
                return "N/A";
            }

            return base.FormatCursorLabel(dataValue);
        }

        public override string FormatLabel(IComparable dataValue)
        {
            if (dataValue == null)
            {
                return "N/A";
            }

            var date = Convert.ToDateTime(dataValue);

            if (date.Year == 1)
            {
                return "N/A";
            }

            return base.FormatLabel(dataValue);
        }
    }
  • You must to post comments
Showing 3 results
Your Answer

Please first to submit.