Tooltip

23 Jun 202311 minutes to read

Stock Chart will display details about the points through tooltip, when the mouse is moved over the point.

Default tooltip

By default, tooltip is not visible. Enable the tooltip by setting Enable property to true .

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

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

    <script>
        var data = window.chartData;
        function stockload(args) {
            args.stockChart.tooltip = { 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();
        }
    }
}

Format the tooltip

By default, tooltip shows information of x and y value in points. In addition to that, you can show more information in tooltip. For example the format ${series.name} ${point.x} shows series name and point x value.

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

            @(Html.EJS().StockChart("container").Load("stockload").Title("AAPL Stock Price")
                                                                .Series(sr =>
                                                                {
                                                                    sr.Type(Syncfusion.EJ2.Charts.ChartSeriesType.Candle).DataSource("data").Add();
                                                                })
                                   .Tooltip(tp => tp.Enable(true).Header("Unemployment").Format("<b>${point.x} : ${point.y}</b>"))
                                                                .Render())

    <script>
        var data = window.chartData;
    </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();
        }
    }
}

Position the tooltip

By default, the tooltip is positioned at the left side of the stock chart. You can move the tooltip along with the mouse by setting Nearest to the Position property.

<script src="stock-chart/stockchart-feature/position/financialdata.js"></script>

@(Html.EJS().StockChart("container").Load("stockload").Title("AAPL Stock Price")
        .Series(sr =>
        {
            sr.Type(Syncfusion.EJ2.Charts.ChartSeriesType.Candle).DataSource("data").Add();
        })
        .Tooltip(tp => tp.Enable(true).Shared(true).Position("Nearest"))
        .Render())

    <script>
        var data = window.chartData;
    </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();
        }
    }
}

Customize the appearance of the tooltip

The Fill and Border properties are used to customize the background color and border of the tooltip respectively. The TextStyle property in the tooltip is used to customize the font of the tooltip text.

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

            @(Html.EJS().StockChart("container").Load("stockload").Title("AAPL Stock Price")
                                                                .Series(sr =>
                                                                {
                                                                    sr.Type(Syncfusion.EJ2.Charts.ChartSeriesType.Candle).DataSource("data").Add();
                                                                })
                                   .Tooltip(tp => tp.Enable(true).Format("${point.x} : ${point.y}").Fill("#7bb4eb")))
                                                                .Render())

    <script>
        var data = window.chartData;
          function stockload(args) {
             args.stockChart.tooltip = {
                    border: {
                     width: 2,
                     color: 'grey'
                 }

             };
          }
    </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();
        }
    }
}