buildChart function

Widget buildChart(
  1. BuildContext context,
  2. OpenUiNode node
)

Chart(type, data, x?, series?, format?, currency?, stacked?, height?).

Implementation

Widget buildChart(BuildContext context, OpenUiNode node) {
  final spec = ChartSpec.from(node.props, locale: node.locale);
  if (spec == null) {
    return const Directionality(
      textDirection: TextDirection.ltr,
      child: SizedBox(height: 240),
    );
  }
  final l10n = OpenUiLocalizations.of(context);
  final pie = spec.type == 'pie' || spec.type == 'donut';
  return Directionality(
    textDirection: TextDirection.ltr,
    child: Semantics(
      label: l10n.chartLabel(
        spec.type,
        pie
            ? (spec.series.firstOrNull ?? l10n.chartValues)
            : spec.series.join(', '),
        spec.x,
      ),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.stretch,
        mainAxisSize: MainAxisSize.min,
        children: [
          if (pie) _PieChart(spec) else _PlotChart(spec),
          if (!pie && spec.series.length > 1) ...[
            const SizedBox(height: 10),
            _Legend(spec.series),
          ],
        ],
      ),
    ),
  );
}