Period selector

17 Feb 20228 minutes to read

The period selector allows to select a range with specified periods. By default the period selector is enabled in stock chart.

Periods

Periods is an array of objects that allows users to specify the range of [Periods] (https://help.syncfusion.com/cr/aspnetcore-js2/Syncfusion.EJ2.Charts.StockChart.html#Syncfusion_EJ2_Charts_StockChart_Periods). The Interval property specifies the count value of the button, and the Text property specifies the text to be displayed on button. The IntervalType property allows users to customize the intervals of the buttons. The IntervalType property supports the following interval types:

  • Auto
  • Years
  • Quarter
  • Months
  • Weeks
  • Days
  • Hours
  • Minutes
  • Seconds
@(Html.EJS().StockChart("container").Load("stockload").Title("AAPL Stock Price").ExportType(new List<Object>() { }).SeriesType(new List<Object>() { }).IndicatorType(new List<Object>() { }).TrendlineType(new List<Object>() { })
                .PrimaryXAxis(xaxis =>xaxis.MajorGridLines(mg=>mg.Color("transparent")
                ))
                .PrimaryYAxis(yaxis =>yaxis.MajorTickLines(mt=>mt.Color("transparent").Width(0)
               ).LineStyle(ls=>ls.Color("transparent")).Crosshair(cr => cr.Enable(true)))

                                                                .Series(sr =>
                                                                {
                                                                    sr.Type(Syncfusion.EJ2.Charts.ChartSeriesType.Line).XName("X").YName("Y").Name("google").DataSource("data").Add();
                                                                })
      .Periods(pr =>
         {
            pr.IntervalType(Syncfusion.EJ2.Charts.RangeIntervalType.Minutes).Interval(1).Text("1M").Add();
            pr.IntervalType(Syncfusion.EJ2.Charts.RangeIntervalType.Minutes).Interval(30).Text("30M").Add();
            pr.IntervalType(Syncfusion.EJ2.Charts.RangeIntervalType.Hours).Interval(1).Text("1H").Add();
            pr.IntervalType(Syncfusion.EJ2.Charts.RangeIntervalType.Hours).Interval(12).Text("12H").Selected(true).Add();
           }
        )
                                                                .Render())

    <script>
        var series1 = [];
        var point1;
        var value = 80;
        var i;

        for (i = 1; i < 500; i++) {
            if (Math.random() > .5) {
                value += Math.random();
            } else {
                value -= Math.random();
            }
            point1 = { x: new Date(2000, 1, 1, 0, i), y: value.toFixed(1) };
            series1.push(point1);
        }

        var data = series1;
      
    </script>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;

namespace EJ2CoreSampleBrowser.Controllers.StockChart
{
    public partial class StockChartController : Controller
    {
        public IActionResult Default()
        {
            return View();
        }
    }
}

Visibility of period selector

The EnablePeriodSelector property allows users to toggle the visibility of period selector.

<script src="~/financial-data.js"></script>

            @(Html.EJS().StockChart("container").Load("stockload").Title("AAPL Stock Price").EnablePeriodSelector(false)
                                                                .Series(sr =>
                                                                {
                                                                    sr.Type(Syncfusion.EJ2.Charts.ChartSeriesType.Candle).DataSource("data").Add();
                                                                })
                                                                .Render())

    <script>
        var data = window.chartData;
        function stockload(args) {
            args.stockChart.crosshair = { enable: true };
        }
    </script>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;

namespace EJ2CoreSampleBrowser.Controllers.StockChart
{
    public partial class StockChartController : Controller
    {
        public IActionResult Default()
        {
            return View();
        }
    }
}