Search results

Tooltip in ASP.NET Core Stock Chart control

15 Oct 2021 / 1 minute 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 enableproperty to true .

tagHelper
tooltip.cs
Copied to clipboard
<ejs-stockchart id="stockchart" load="stockload" title="AAPL Stock Price">
                <e-stockchart-series-collection>
                    <e-stockchart-series type='Candle' xName="x"> </e-stockchart-series>
                </e-stockchart-series-collection>
                <e-stockchart-tooltipsettings enable="true"></e-stockchart-tooltipsettings>
            </ejs-stockchart>

    <script src="~/financial-data.js"></script>
    <script>
        var data = chartData;
            function stockload(args) {
                args.stockChart.series[0].dataSource = data;
            }
    </script>
Copied to clipboard
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.

tagHelper
format.cs
Copied to clipboard
<ejs-stockchart id="stockchart" load="stockload" title="AAPL Stock Price">
                <e-stockchart-series-collection>
                    <e-stockchart-series type='Candle' xName="x"> </e-stockchart-series>
                </e-stockchart-series-collection>
             <e-stockchart-tooltipsettings enable="true" header="Unemployment" format="<b>${point.x} : ${point.y}</b>"></e-stockchart-tooltipsettings>
            </ejs-stockchart>
        </div>

    <script src="~/scripts/chart/financial-data.js"></script>
    <script>
        var data = chartData;
            function stockload(args) {
                args.stockChart.series[0].dataSource = data;
            }
    </script>
Copied to clipboard
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 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.

tagHelper
customtooltip.cs
Copied to clipboard
<ejs-stockchart id="stockchart" load="stockload" title="AAPL Stock Price">
                <e-stockchart-series-collection>
                    <e-stockchart-series type='Candle' xName="x"> </e-stockchart-series>
                </e-stockchart-series-collection>
                <e-stockchart-tooltipsettings enable="true" format="${point.x} : ${point.y}" fill="#7bb4eb"> 
                </e-stockchart-tooltipsettings>
            </ejs-stockchart>

    <script src="~/scripts/chart/financial-data.js"></script>
    <script>
        var data = chartData;
        function stockload(args) {
            args.stockChart.series[0].dataSource = data;
            args.stockChart.tooltip = {
                border: {
                    width: 2,
                    color: 'grey'
                }

            };
        }

    </script>
Copied to clipboard
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();
        }
    }
}