How to remove double y-axis labels and yellow lines in Flutter chart?

316 Views Asked by At

I'm working on a Flutter chart and I'm encountering two issues:

1. Double Y-Axis Labels: The y-axis is displaying duplicate labels for some values. How can I fix this to show only one label per value?

2. Yellow Lines: Yellow lines appear underneath my chart. What might cause these lines and how do I remove them?

Image:

chart demonstrating the issue

Code:

import 'package:fl_chart/fl_chart.dart';
import 'package:flutter/material.dart';

class LineTitles {
  static GetTitleData() => FlTitlesData(
      show: true,
      bottomTitles: AxisTitles(
        sideTitles: SideTitles(
            showTitles: true,
            reservedSize: 35,
            getTitlesWidget: (value, meta) {
              switch (value.toInt()) {
                case 2:
                  return Text(
                    'MAR',
                    style: TextStyle(
                      color: Color(0xff68737d),
                      fontWeight: FontWeight.bold,
                      fontSize: 16,
                    ),
                  );
                case 5:
                  return Text(
                    'JUN',
                    style: TextStyle(
                      color: Color(0xff68737d),
                      fontWeight: FontWeight.bold,
                      fontSize: 16,
                    ),
                  );
                case 8:
                  return Text('SEP',
                      style: TextStyle(
                        color: Color(0xff68737d),
                        fontWeight: FontWeight.bold,
                        fontSize: 16,
                      ));
              }
              return Text(" ");
            }),

      ),
      leftTitles: AxisTitles(
          sideTitles: SideTitles(
              showTitles: true,
              reservedSize: 35,
              getTitlesWidget: (value, meta) {
                switch (value.toInt()) {
                  case 1:
                    return Text(
                      '10k',
                      style: TextStyle(
                        color: Color(0xff68737d),
                        fontWeight: FontWeight.bold,
                        fontSize: 15,
                      ),
                    );
                  case 3:
                    return Text(
                      '30k',
                      style: TextStyle(
                        color: Color(0xff68737d),
                        fontWeight: FontWeight.bold,
                        fontSize: 15,
                      ),
                    );
                  case 5:
                    return Text('50k',
                        style: TextStyle(
                          color: Color(0xff68737d),
                          fontWeight: FontWeight.bold,
                          fontSize: 15,
                        )
                    );

                }
                return Text(" ");
              },

          )));
}

Things I've tried:

I tried uninstalling and reinstalling the app, but it didn't resolve the issues.

3

There are 3 best solutions below

0
Delwinn On BEST ANSWER

Use Scaffold as your parent widget.

Scaffold(
  body: ///rest of your widgets here
)
0
Abdallah A. Odeh On

Your screen must have a Scaffold as a root widget, the screen you are rendering the chart in, grap what’s inside the build function

return Scaffold(
    body: //paste here,
);
0
Dee S On

You have to wrap your code in a Material() Widget,

could be:

1-

Material( child: YOUR_WIDGET_HERE);

2-

Scaffold(body: YOUR_WIDGET_HERE);

This happens because your Widget should have a Material() Widget as parent, in the Widget Tree