# chart-live-chart

> Real-time Candlestick chart streaming live AAPL OHLC ticks with crosshair and last-value label.

**Framework:** aspnet-core  **Component:** Chart  **Variant:** live-chart

## Get this item

**If you are an agent, fetch the JSON.** Source is inlined, so one request is enough and no tooling is required:

```
GET https://ai.syncfusion.com/r/aspnet-core/chart-live-chart.json
```

**Install Package(s)**

```bash
dotnet add package Syncfusion.AspNetCore.Charts
```

**Notes**

- Syncfusion release: 2026 Volume 3 (v35.1.37)
- The Syncfusion package is licensed. The composition in this file is source you own and edit. See https://ai.syncfusion.com/licensing.md

## Source files

### src/components/chart-live-chart/chart.cshtml

```cshtml
@page
@namespace aspnet_core.Chart.LiveStockData
@model EJ2CoreSampleBrowser.Chart.LiveStockData.LiveStockDataModel
@using Syncfusion.EJ2

    <div class="control-section" align="center">
        <ejs-chart id="stock" title="Live Stock Data" load="load" axisRangeCalculated="axisRangeCalculated">
            <e-chart-primaryxaxis valueType="@Syncfusion.EJ2.Charts.ValueType.DateTime" labelIntersectAction="@Syncfusion.EJ2.Charts.LabelIntersectAction.Hide">
                <e-majorgridlines width="0"></e-majorgridlines>
                <e-crosshairtooltip enable="true"></e-crosshairtooltip>
            </e-chart-primaryxaxis>
            <e-chart-primaryyaxis minimum="90" interval="10" opposedPosition="true">
                <e-majorgridlines width="1"></e-majorgridlines>
                <e-majorticklines width="0"></e-majorticklines>
                <e-linestyle width="0"></e-linestyle>
                <e-crosshairtooltip enable="true"></e-crosshairtooltip>
            </e-chart-primaryyaxis>
            <e-chart-chartarea>
                <e-chartarea-border width="0"></e-chartarea-border>
            </e-chart-chartarea>
            <e-chart-crosshairsettings enable="true" dashArray="5,5"></e-chart-crosshairsettings>
            <e-series-collection>
                <e-series xName="x" low="low" high="high" open="open" close="close" type="@Syncfusion.EJ2.Charts.ChartSeriesType.Candle" bearFillColor="#2ecd71" bullFillColor="#e74c3d" columnWidth="0.4">
                    <e-series-lastvaluelabel enable="true" dashArray="3,2" background="red" lineWidth="0.5">
                        <e-font size="10px"></e-font>
                    </e-series-lastvaluelabel>
                </e-series>
            </e-series-collection>
        </ejs-chart>
    </div>

    <script>
        // Seed the series with a small set of candles, then append a new
        // candle every second to simulate a live feed.
        var intervalId;

        function createSeedData() {
            var series = [];
            var base = 150;
            for (var i = 0; i < 10; i++) {
                var open = base + (i % 3) * 2;
                var close = open + ((i % 2 === 0) ? 3 : -2);
                series.push({
                    x: new Date(2024, 0, 1, 9, 30, i * 5),
                    open: open,
                    high: Math.max(open, close) + 2,
                    low: Math.min(open, close) - 2,
                    close: close
                });
            }
            return series;
        }

        function load(args) {
            args.chart.series[0].dataSource = createSeedData();
            args.chart.width = ej.base.Browser.isDevice ? "100%" : "90%";
            startFeed(args.chart);
        }

        function startFeed(chart) {
            clearFeed();
            intervalId = setInterval(function () {
                if (!chart || !chart.series || chart.series.length === 0) {
                    clearFeed();
                    return;
                }
                var points = chart.series[0].dataSource;
                var last = points[points.length - 1];
                var nextClose = last.close + (Math.random() < 0.5 ? -1 : 1) * Math.random() * 3;
                nextClose = Math.max(95, Math.min(200, nextClose));
                chart.series[0].addPoint({
                    x: new Date(new Date(last.x).getTime() + 60000),
                    open: last.close,
                    high: Math.max(last.close, nextClose) + 1,
                    low: Math.min(last.close, nextClose) - 1,
                    close: nextClose
                });
            }, 1000);
        }

        function clearFeed() {
            if (intervalId) {
                clearInterval(intervalId);
                intervalId = null;
            }
        }

        function axisRangeCalculated(args) {
            // Keep the time axis pinned to the most recent candles.
            if (args.axis.name === 'primaryXAxis') {
                var points = args.axis.series[0].points;
                if (points.length > 0) {
                    args.maximum = new Date(points[points.length - 1].x).getTime() + 60000;
                    args.minimum = new Date(points[0].x).getTime() - 60000;
                }
            }
        }
    </script>

```

### src/components/chart-live-chart/chart.cshtml.cs

```cs
using System;
using System.Collections.Generic;
using Microsoft.AspNetCore.Mvc.RazorPages;

namespace EJ2CoreSampleBrowser.Chart.LiveStockData
{
    public class LiveStockDataModel : PageModel
    {
        public DateTime SelectedDate { get; set; } = DateTime.Today;

        public void OnGet()
        {
        }
    }
}

```
