Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

problems with tick step values on X axis #1267

Closed
Evaldas256 opened this issue Feb 19, 2023 · 5 comments · Fixed by #1454
Closed

problems with tick step values on X axis #1267

Evaldas256 opened this issue Feb 19, 2023 · 5 comments · Fixed by #1454
Labels
enhancement New feature or request Fundamental

Comments

@Evaldas256
Copy link

I am having problem setting tick step for 0.05 in X axis in LineChart. Tick step is displayed 0.1. Value which should be 0.05 displayed as 0.1.
My code:
`// Automatic FlutterFlow imports
import '../../flutter_flow/flutter_flow_theme.dart';
import '../../flutter_flow/flutter_flow_util.dart';
import '../widgets/index.dart'; // Imports other custom widgets
import '../actions/index.dart'; // Imports custom actions
import '../../flutter_flow/custom_functions.dart'; // Imports custom functions
import 'package:flutter/material.dart';
// Begin custom widget code
// DO NOT REMOVE OR MODIFY THE CODE ABOVE!

import 'package:fl_chart/fl_chart.dart';

class MyData {
final double x;
final double y;

MyData(this.x, this.y);
}

class LinearGraphWidget extends StatefulWidget {

const LinearGraphWidget({
Key? key,
this.width,
this.height,
required this.duomenys,
required this.name,
}) : super(key: key);

final double? width;
final double? height;
final List duomenys;
final String name;

@OverRide
_LinearGraphWidgetState createState() => _LinearGraphWidgetState();
}

class _LinearGraphWidgetState extends State {

duomenu_konvertavimas(){
double force;
double displacement;
List data=[];

for (int i = 0; i < widget.duomenys.length; i++) {
displacement = double.parse(widget.duomenys[i]['displacement']);
force = double.parse(widget.duomenys[i]['force']);
data.add(FlSpot(force,displacement));
}
return data;
}

Widget topTitleWidgets(double value, TitleMeta meta) {
if (value % 1 != 0) {
return Container();
}
const style = TextStyle(
fontSize: 8,

fontWeight: FontWeight.bold,

);
return SideTitleWidget(
axisSide: meta.axisSide,
child: Text(value.toDouble().toString(), style: style),
);
}

Widget rightTitleWidgets(double value, TitleMeta meta) {
final style = TextStyle(

  fontWeight: FontWeight.bold,
  fontSize: 12,
);
final intValue = reverseY(value, 0, 0.5).toDouble();

if (intValue == (6 + 0)) {
  return Text('', style: style);
}

return Text(intValue.toString(), style: style, textAlign: TextAlign.right);

}

Widget leftTitleWidgets(double value, TitleMeta meta) {
final style = TextStyle(

  fontWeight: FontWeight.bold,
  fontSize: 12,
);

final intValue = reverseY(value, 0, 6).toDouble();

if (intValue == (6 + 0)) {
  return Text('', style: style);
}

return Padding(
  padding: const EdgeInsets.only(right: 6),
  child: Text(
    intValue.toString(),
    style: style,
    textAlign: TextAlign.center,
  ),
);

}

@OverRide
Widget build(BuildContext context){
return AspectRatio(
aspectRatio: 1.5,
child: LineChart(
LineChartData(
minX: 0,
maxX: 0.5,
minY: 0,
maxY: 6,
lineBarsData: [
LineChartBarData(
// spots: duomenu_konvertavimas(),
isCurved: false,
spots: reverseSpots(duomenu_konvertavimas(), 0, 6),
barWidth: 1,
dotData: FlDotData(
show: true,
getDotPainter: (spot, percent, barData, index) =>
FlDotCirclePainter(
radius: 1,
color: Colors.transparent,

            ),
      ),
            belowBarData: BarAreaData(
              show: false,
            )

        ),
      ],

      titlesData: FlTitlesData(

        leftTitles: AxisTitles(
          sideTitles: SideTitles(
            interval: 0.5,
            showTitles: true,
             getTitlesWidget: leftTitleWidgets,
            reservedSize: 40,
          ),
        ),
        rightTitles: AxisTitles(
          sideTitles: SideTitles(
            interval: 0.5,
            showTitles: false,
            getTitlesWidget: rightTitleWidgets,
            reservedSize: 40,
          ),
        ),
        bottomTitles: AxisTitles(
          sideTitles: SideTitles(

              interval: 0.05,
              showTitles:true),

        ),
        topTitles: AxisTitles(
          sideTitles: SideTitles(

            interval:0.05,
            showTitles: true,
            reservedSize: 40,

            // getTitlesWidget: topTitleWidgets,
          ),
        ),
      ),

      gridData: FlGridData(
        show: true,
        drawVerticalLine: true,
        horizontalInterval: 0.5,
        checkToShowHorizontalLine: (value) {
          final intValue = reverseY(value, 0, 6).toDouble();

          if (intValue == (6).toDouble()) {
            return false;
          }

          return true;
        },
      ),
    ),
  ),
);

}
}
double reverseY(double y, double minX, double maxX) {
return (maxX + minX) - y;
}

List reverseSpots(List inputSpots, double minY, double maxY) {
return inputSpots.map((spot) {
return spot.copyWith(y: (maxY + minY) - spot.y);
}).toList();
}
`
Screenshot 2023-02-19 155922

@imaNNeo
Copy link
Owner

imaNNeo commented Feb 21, 2023

Please check your description. Your reproducible code is not formatted correctly.
Thanks

@mai-nakagawa
Copy link

@imaNNeo Hello, I'm also facing the same problem. This is the reproducible code:

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

class ScatterChartSample extends StatelessWidget {
  const ScatterChartSample({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text("Scatter Chart Sample"),
      ),
      body: ScatterChart(
        ScatterChartData(
          scatterSpots: [
            ScatterSpot(0.00001, 0.09, radius: 6),
            ScatterSpot(0.00002, 0.0800005, radius: 6),
            ScatterSpot(0.00001, 0.0745675, radius: 6),
            ScatterSpot(0.00007, 0.036897, radius: 6),
          ],
          minX: 0,
          maxX: 0.0001,
          minY: 0,
          maxY: 0.1,
        ),
      ),
    );
  }
}

void main() => runApp(const MaterialApp(home: ScatterChartSample()));

And this is the scatter chart generated by the code:
scatter_chart

@mai-nakagawa
Copy link

I think it's not a bug but by design. I found the following line to accept only 1 decimal place:

resultNumber = number.toStringAsFixed(1);

Would be great if it accepts more decimal places.

@imaNNeo imaNNeo added enhancement New feature or request Fundamental and removed Needs Reproducible Code labels Oct 7, 2023
@imaNNeo
Copy link
Owner

imaNNeo commented Oct 7, 2023

Thank you @mai-nakagawa
I'm gonna fix it

@imaNNeo
Copy link
Owner

imaNNeo commented Oct 7, 2023

Fixed in 0.64.0

ChrGrb pushed a commit to ChrGrb/fl_chart that referenced this issue Oct 7, 2023
OlehSv pushed a commit to Oleh-Sv/fl_chart that referenced this issue May 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request Fundamental
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants