Pre loader

Specifying Text Labels with ILabelProvider Tutorial doesn't work for me

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

Hi

I’ve followed your example for a Custom Label on X axis , I changed from the init parameter from IAxis to IAxisCore as defined in ProviderBase, otherwise it wouldn’t have compile. But after passing from public override string FormatLabel I got this error

Unable to cast object of type 'SciChart.Charting.Visuals.Axes.LabelProviders.DefaultTickLabelViewModel' to type 'SciChart.Charting.Visuals.Axes.LabelProviders.NumericTickLabelViewModel'.

Here my definition of the XAxis

  <s:NumericAxis x:Name="MainChartXAxis" 

                     VisibleRangeChanged="XAxis_VisibleRangeChanged"
                        AutoTicks="False"
                           AxisTitle="Programming Language"
                           LabelProvider="{Binding XLabelFormatter}"
                           MajorDelta="1"
                           MinorDelta="0.2"
                           VisibleRange="-0.5,4.5"
                      >
            </s:NumericAxis>

I have a BaseRenderableSeries defined as follows

      <s:SciChartSurface Name="sciChart" 
                    Grid.Row="0"
                    BorderThickness="0"

                    Padding="0"
                       s:SciChartGroup.VerticalChartGroup="myCharts"
                    >

        <!--  Declare RenderableSeries  -->
        <s:SciChartSurface.RenderableSeries>
            <s:FastLineRenderableSeries x:Name="lineSeries"

                                  StrokeThickness="2"
                                  PaletteProvider="{StaticResource GainLossPaletteProvider}"
                                  s:CursorModifier.TooltipTemplate="{StaticResource CursorTooltipTemplate}"
                                 >
                <s:FastLineRenderableSeries.PointMarker>
                    <seriesWithMetadata:AnnotatedPointMarker RenderPD="{Binding ElementName=lineSeries,Path=.}" Width="5" Height="7" GainMarkerFill="LimeGreen" LossMarkerFill="Red" Stroke="White" StrokeThickness="1"/>
                </s:FastLineRenderableSeries.PointMarker>

            </s:FastLineRenderableSeries>
            <s:FastLineRenderableSeries x:Name="FastLineSeries" />
        </s:SciChartSurface.RenderableSeries>

am I doing something wrong?

  • You must to post comments
Best Answer
0
0

Hi Lorenzo,

The Heatmap With Text example in our WPF Examples Suite actually includes a LabelProvider. If you have a look at the source-code, it can help you.

The LabelProvider is declared like this

    class YAxisLabelProvider: LabelProviderBase
    {
        public override string FormatLabel(IComparable dataValue)
        {
            var day = Convert.ToInt32(dataValue);
            switch (day)
            {
                case 0: return "Mon";
                case 1: return "Tue";
                case 2: return "Wed";
                case 3: return "Thu";
                case 4: return "Fri";
                case 5: return "Sat";
                case 6: return "Sun";
            }
            return "";
        }

        public override string FormatCursorLabel(IComparable dataValue)
        {
            return FormatLabel(dataValue);
        }
    }

    class XAxisLabelProvider : LabelProviderBase
    {
        public override string FormatLabel(IComparable dataValue)
        {
            var h = Convert.ToInt32(dataValue);
            var dt = new DateTime(2000, 1, 1, 1, 0, 0).AddHours(h);
            return dt.ToString("hh:mm tt", new CultureInfo("en-US"));
        }

        public override string FormatCursorLabel(IComparable dataValue)
        {
            return FormatLabel(dataValue);
        }
    }

And assigned like this

yAxis.LabelProvider = new YAxisLabelProvider();
  • lorenzo522
    That was what I was looking for. Thank you
  • You must to post comments
Showing 1 result
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