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

0
0

Hello

I tried to create a TickProvider for DateTimeaxis followed by https://www.scichart.com/documentation/win/current/webframe.html#Axis%20Ticks%20-%20TickProvider%20and%20DeltaCalculator%20API.html .

My custom provider (CustomDateTimeTickProvider) exactly same that found in url above.

<s:SciChartSurface x:Name="sciChartrtr" 
      s:ThemeManager.Theme="Chrome"
      RenderableSeries="{s:SeriesBinding ChartSeries, UpdateSourceTrigger=PropertyChanged}">
         <s:SciChartSurface.Resources>
             <vm:CustomTickProvider  x:Key="CustomTickProvider"/>
         </s:SciChartSurface.Resources>

         <s:SciChartSurface.XAxis>
               <s:DateTimeAxis DrawMajorBands="True" TickProvider="{StaticResource CustomTickProvider}" AutoTicks="True"  TextFormatting="yyyy.MM.dd" AxisTitle="Idő"/>
          </s:SciChartSurface.XAxis>
          <s:SciChartSurface.YAxis>
                <s:NumericAxis AutoRange="Always" DrawMajorBands="True" AxisAlignment="Left" GrowBy="0.02, 0.02" AxisTitle="{Binding SecondYAxisTitle}"/>
           </s:SciChartSurface.YAxis>
           <!-- YAxis, RenderableSeries omitted for brevity -->
 </s:SciChartSurface>

But my xaxis is empty. What do I wrong?
Thank you very much

Version
6
  • You must to post comments
0
0

Hi Hakan,

The DateTimeAxis requires a TickProvider which inherits DateTimeTickProvider. The one you’ve used is for a NumericAxis

In the same Documentation Link please scroll down and you should see this code. Can you try it?

Creating a custom TickProvider for a TimeSpanAxis or DateTimeAxis
The process for creating a TickProvider for a TimeSpanAxis or DateTimeAxis is similar, except you need to change the base class and return TimeSpan, or DateTime arrays.

// 1. Create a class which inherits DateTimeTickProvider
  // 2. Return an array of IComparable, but actual elements must be DateTimes
  // 3. Assign to the DateTimeAxis.TickProvider property
  public class CustomDateTimeTickProvider : DateTimeTickProvider
  {
         public override IComparable[] GetMajorTicks(IAxisParams axis)
         {
               // TODO: calculate ticks
               return new IComparable[]
               {
                      new DateTime(2015, 01, 01),
                      new DateTime(2015, 01, 02),
                      new DateTime(2015, 01, 03),
                      // ...
               };
         }
         public override IComparable[] GetMinorTicks(IAxisParams axis)
         {
               // TODO: calculate ticks
               return new IComparable[]
               {
                      new DateTime(2015, 01, 01),
                      new DateTime(2015, 01, 02),
                      new DateTime(2015, 01, 03),
                      // ...
               };
         }
  }
  

Best regards,
Andrew

  • You must to post comments
0
0

Thanks for your answer.
No, I use DateTimeAxis in XAML:

<s:SciChartSurface.XAxis>
     <s:DateTimeAxis DrawMajorBands="True" TickProvider="{StaticResource CustomTickProvider}" AutoTicks="True"  TextFormatting="yyyy.MM.dd" AxisTitle="Idő"/>
  </s:SciChartSurface.XAxis>

My CustomTickProvider is this: (I renamed CustomDateTimeTickProvider found in example to simple CustomTickProvider)

public class CustomTickProvider : DateTimeTickProvider
{
    public override IList<IComparable> GetMajorTicks(IAxisParams axis)
    {
        // TODO: calculate ticks
        return new IComparable[]
        {
                new DateTime(2015, 01, 01),
                new DateTime(2015, 01, 02),
                new DateTime(2015, 01, 03),
            // ...
        };
    }

    public override IList<IComparable> GetMinorTicks(IAxisParams axis)
    {
        // TODO: calculate ticks
        return new IComparable[]
        {
                new DateTime(2015, 01, 01),
                new DateTime(2015, 01, 02),
                new DateTime(2015, 01, 03),
            // ...
        };
    }
}

When I debug code, the program run into GetMajorTicks function, so the function returns with the correct IList which contains the given dates, but there aren’t any displayed ticks on xaxis.

  • You must to post comments
0
0

Ok, the example works , I made some mistakes, sorry-

I created the custom tick provider, added to axis, but some label are displayed only, not all. How can I control displaying of label of ticks?
Thank you

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

Please first to submit.