Hamza Ali
Hamza Ali

Reputation: 170

Is there any option to specify Interval between values on x and y axis in flutter fl_charts?

enter image description here

LineChart(
    LineChartData(
        minX: 0,
        maxX: 40,
        minY: 0,
        lineBarsData: [
            LineChartBarData(
                spots: fl,
                isCurved: true,
                barWidth: 5,
            )
        ]
    )
),

here is my code values on x axis are overlapping. I am using fl_charts for flutter is there any option to specify intervals between axis value?

Upvotes: 0

Views: 4697

Answers (1)

Toqeer Yousaf
Toqeer Yousaf

Reputation: 414

LineChartData(
  minX: 0,
  maxX: 40,
  gridData: FlGridData(
    show: false,
  ),
  titlesData: FlTitlesData(
    bottomTitles: SideTitles(
      showTitles: true,
      reservedSize: 22,
      getTextStyles: (value) => const TextStyle(
        color: CColors.pink,
        fontWeight: FontWeight.bold,
        fontSize: 16,
      ),
      margin: 10,
      getTitles: (value) {
        if (value.toInt() % 5 == 0) {
          return '${value.toInt()}';
        } else {
          return '';
        }
      },
    ),
    leftTitles: SideTitles(
      showTitles: true,
      getTextStyles: (value) => const TextStyle(
        color: CColors.pink,
        fontWeight: FontWeight.bold,
        fontSize: 14,
      ),
      getTitles: (value) {
        if (value.toInt() % 25 == 0) {
          return '${value.toInt()}';
        } else {
          return '';
        }
      },
      margin: 8,
      reservedSize: 30,
    ),
  ),
  borderData: FlBorderData(
    show: true,
  ),
  lineBarsData: [
    LineChartBarData(
      spots: fl,
      colors: [CColors.pink],
      barWidth: 5,
    ),
  ],
),

Upvotes: 1

Related Questions