Search results

Candle in Blazor Chart component

28 Jul 2021 / 2 minutes to read

Candle

Candle series are similar to Hilo Open Close series, are used to represent the Low, High, Open and Closing price over time. To render a candle series, use series Type as Candle.

candle.razor
Copied to clipboard
@using Syncfusion.Blazor.Charts

<SfChart>
    <ChartPrimaryXAxis ValueType="Syncfusion.Blazor.Charts.ValueType.Category">
    </ChartPrimaryXAxis>

    <ChartSeriesCollection>
        <ChartSeries DataSource="@StockDetails" XName="X" High="High" Low="Low" Type="ChartSeriesType.Candle" Open="Open" Close="Close">
        </ChartSeries>
    </ChartSeriesCollection>
</SfChart>

@code{
    public class Data
    {
        public string X {get; set;}
        public double Y {get; set; }
        public double High {get; set; }
        public double Low {get; set; }
        public double Open {get; set; }
        public double Close { get; set;}
    }

    public List<Data> StockDetails = new List<Data>
{
        new Data{ X= "Jan", Open= 120, High= 160, Low= 100, Close= 140 },
        new Data{ X= "Feb", Open= 150, High= 190, Low= 130, Close= 170 },
        new Data{ X= "Mar", Open= 130, High= 170, Low= 110, Close= 150 },
        new Data{ X= "Apr", Open= 160, High= 180, Low= 120, Close= 140 },
        new Data{ X= "May", Open= 150, High= 170, Low= 110, Close= 130 }
    };
}

Candle

Hollow Candle

Candle series chart allows to visually compare the current price with previous price by customizing the appearance. Candles are filled/left as hollow based on the following criteria.

States Description
Filled Candle sticks are filled when the close value is lesser than the open value.
Unfilled Candle sticks are unfilled when the close value is greater than the open value.

The color of the candle will be defined by comparing with previous values. BearFillColor property is used to apply when the current closing value is greater than the previous closing value and BullFillColor will be applied when the current closing value is less than the previous closing value. By default, BullFillColor is red and BearFillColor is green.

Solid Candles

EnableSolidCandles is used to enable/disable the solid candles. By default it is set as false. The fill color of the candle will be defined by its opening and closing values. BearFillColor will be applied when the opening value is less than the closing value. BullFillColor will be applied when the opening value is greater than closing value.

solid-candles.razor
Copied to clipboard
@using Syncfusion.Blazor.Charts

<SfChart>
    <ChartPrimaryXAxis ValueType="Syncfusion.Blazor.Charts.ValueType.Category">
    </ChartPrimaryXAxis>
    <ChartSeriesCollection>
        <ChartSeries DataSource="@StockDetails" XName="X" High="High" BearFillColor="#e56590" BullFillColor="#f8b883" EnableSolidCandles="true"
                     Low="Low" Type="ChartSeriesType.Candle" Open="Open" Close="Close">
        </ChartSeries>
    </ChartSeriesCollection>
</SfChart>

@code{
    public class Data
    {
        public string X { get; set; }
        public double Y { get; set; }
        public double High { get; set; }
        public double Low { get; set; }
        public double Open { get; set; }
        public double Close { get; set; }
    }

    public List<Data> StockDetails = new List<Data>
{
        new Data{ X= "Jan", Open= 120, High= 160, Low= 100, Close= 140 },
        new Data{ X= "Feb", Open= 150, High= 190, Low= 130, Close= 170 },
        new Data{ X= "Mar", Open= 130, High= 170, Low= 110, Close= 150 },
        new Data{ X= "Apr", Open= 160, High= 180, Low= 120, Close= 140 },
        new Data{ X= "May", Open= 150, High= 170, Low= 110, Close= 130 }
    };
}

Solid Candles

Refer to our Blazor Charts feature tour page for its groundbreaking feature representations and also explore our Blazor Chart example to know various chart types and how to represent time-dependent data, showing trends at equal intervals.

See Also