Articles in this section
Category / Section

How to render Flutter candlestick chart using the charts widget (SfCartesianChart) ?

1 min read

In this article, we explain how to render a candlestick chart using Syncfusion® Flutter Cartesian Chart widget.

 

Our Cartesian chart widget provides financial chart support. The candlestick provides information about the open, close, high and low price over a particular period. Here if the opening price is higher than the closing price, the candle is filled and if the closing is higher than the opening price, then candle is unfilled. The wick at top represents the highest price and the wick at lower represents the lowest price of a particular period. 

Follow these instructions to render a candlestick chart:

Step 1: Initialize the required data source with x, open, high, low and close values.

List<ChartSampleData> chartData = [
    ChartSampleData(
        xDateTime(20160111),
        open98.97,
        high101.19,
        low95.36,
        close97.13),
    ChartSampleData(
        xDateTime(20160118),
        open98.41,
        high101.46,
        low93.42,
        close101.42),
    ChartSampleData(
        xDateTime(20160125),
        open101.52,
        high101.53,
        low92.39,
        close97.34),
    ChartSampleData(
        xDateTime(20160201),
        open96.47,
        high97.33,
        low93.69,
        close94.02),
    ChartSampleData(
        xDateTime(20160208),
        open93.13,
        high96.35,
        low92.59,
        close93.99),
    ChartSampleData(
        xDateTime(20160215),
        open95.02,
        high98.89,
        low94.61,
        close96.04),
    ChartSampleData(
        xDateTime(20160222),
        open96.31,
        high98.0237,
        low93.32,
        close96.91),
    ChartSampleData(
        xDateTime(20160229),
        open96.86,
        high103.75,
        low96.65,
        close103.01),
    ChartSampleData(
        xDateTime(20160307),
        open102.39,
        high102.83,
        low100.15,
        close102.26),
    ChartSampleData(
        xDateTime(20160316),
        open106.5,
        high106.5,
        low106.5,
        close106.5),
  ];

 

Step 2: Initialize the SfCartesianChart widget with the candle series and map the required parameters i.e xValueMapper,  lowValueMapper, highValueMapper, openValueMapper, and closeValueMapper.

 SfCartesianChart(
    series: <CandleSeries<ChartSampleDataDateTime>>[
        CandleSeries<ChartSampleDataDateTime>(
          dataSource: chartData,
          // To bind x value
          xValueMapper(ChartSampleData sales, _) => sales.x,
          // To bind low value
          lowValueMapper(ChartSampleData sales, _) => sales.low,
          // To bind high value
          highValueMapper(ChartSampleData sales, _) => sales.high,
          // To bind open value
          openValueMapper(ChartSampleData sales, _) => sales.open,
          // To bind close value
          closeValueMapper(ChartSampleData sales, _) => sales.close
        )
    ]
)

 

To know more about candle chart, refer to the Syncfusion® Flutter Cartesian Charts user guide.

 

Screenshot

 

candle_chart

 

View the Github Sample here.

 

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please  to leave a comment
Access denied
Access denied