Skip to content

Candle Chart in Flutter Cartesian Charts: Hide Weekends #500

@MilesAdamson

Description

@MilesAdamson

Hi, I have a chart which is plotting AAPL for the last 2 weeks with a daily candle resolution. It is working beautifully, except for one thing. The weekends and holidays leave empty gaps in the chart. I would like my app to be continuous such that the weekends and holidays which have no data are simply not plotted, which would make my x-axis a bit weird where it would skip days.

How would you suggest modifying my data or plot to make Fridays seamlessly connect to Mondays?

image

@freezed
class Candle with _$Candle {
  Candle._();
  factory Candle(
    double close,
    double high,
    double low,
    double open,
    DateTime timestamp,
    double volume,
  ) = _Candle;

  List<double> get spread => [low, close, open, high];
}
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('Chart'),
      ),
      body: SfCartesianChart(
        primaryXAxis: DateTimeAxis(),
        primaryYAxis: NumericAxis(
          minimum: plotMinimum.roundToDouble(),
          maximum: plotMaximum.roundToDouble(),
          interval: 1,
        ),
        series: <ChartSeries<Candle, DateTime>>[
          widget.candles.candleSeries,
        ],
      ),
    );
  }
    return CandleSeries<Candle, DateTime>(
      xValueMapper: (c, _) => c.timestamp,
      dataSource: this,
      openValueMapper: (c, _) => c.open,
      highValueMapper: (c, _) => c.high,
      closeValueMapper: (c, _) => c.close,
      lowValueMapper: (c, _) => c.low,
      bearColor: Colors.red,
      bullColor: Colors.green,
    );

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions