How to show duplicate axis label on the X-Axis of a BarChart in Flutter Charts?

367

I know this is an old question but for anyone else looking for this, an easy workaround is to symmetrically add spaces to repeated labels. This can be done using a callable class for your domain function, so that you can keep track of repeats:

class Labeler {
  final existingLabels = <String>[];

  String call(Data data, int index) {
    String baseLabel = data.toString();
    int existingCount = existingLabels.where((element) => element == baseLabel).length;
    existingLabels.add(baseLabel);
    return ' ' * existingCount + baseLabel + ' ' * existingCount;
  }
}

You can then create an instance and set it as your domainFn.

Share:
367
Mohtasim
Author by

Mohtasim

Software Engineer with a demonstrated history of working in the research industry. Skilled in C++, Java, Javascript, Dynamic Programming, Graph Theory, Algorithms, Spring-Boot, React, Flutter, React-Native, Android, SQL, Git. Strong engineering professional with a Bachelor of Science (B.Sc.) and Master of Science (M. Sc.) focused in Computer Science and Engineering from Jahangirnagar University.

Updated on December 15, 2022

Comments