Skip to content

Vertical and horizontal misalignment for rotated labels in column chart #191

@hnnngwdlch

Description

@hnnngwdlch

Hi,

I noticed that when I use a column chart and rotate my labels by 90 degrees (in order to align them with the columns), not all of them are rendered correctly.

For some there is a horizontal offset (see data points 2 and 11 in the screenshot) and for others the vertical position seems to be not correct. In this example, despite using ChartDataLabelAlignment.outer, some labels start at the bottom or somewhere else along the respective column of the chart.

class _TestGraphState extends State<TestGraph> {
  @override
  Widget build(BuildContext context) {
    final List<DisplayedData> columnSeriesData = [
      DisplayedData('Sleeping', 8.7),
      DisplayedData('Personal Care', 0.8),
      DisplayedData('Eating and drinking', 1.2),
      DisplayedData('Housework', 1.9),
      DisplayedData('Other', 1.3),
      DisplayedData('Childcare / care for others', 0.7),
      DisplayedData('Working', 3.8),
      DisplayedData('Education', 0.5),
      DisplayedData('Socialization', 0.7),
      DisplayedData('Watching television', 2.7),
      DisplayedData('Exercise / recreation', 0.3),
      DisplayedData('Leisure', 1.4),
    ];
    return Scaffold(
      body: Padding(
        padding: EdgeInsets.symmetric(
          vertical: 20,
          horizontal: 0,
        ),
        child: Column(
          children: <Widget>[
            Text(
              'Graph title',
              style: TextStyle(
                fontSize: 20,
              ),
            ),
            SizedBox(
              height: 15,
            ),
            Expanded(
              child: SfCartesianChart(
                primaryXAxis: CategoryAxis(
                  isVisible: false,
                ),
                series: <ChartSeries>[
                  ColumnSeries<DisplayedData, String>(
                    dataSource: columnSeriesData,
                    xValueMapper: (DisplayedData data, _) => data.xValueMapper,
                    yValueMapper: (DisplayedData data, _) => data.yValueMapper,
                    dataLabelSettings: DataLabelSettings(
                      labelAlignment: ChartDataLabelAlignment.outer,
                      isVisible: true,
                      angle: 90,
                    ),
                    dataLabelMapper: (DisplayedData data, _) =>
                        '${data.yValueMapper} (${data.xValueMapper})',
                  ),
                ],
              ),
            ),
          ],
        ),
      ),
    );
  }
}

image

Best regards,
Henning

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