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

Doesn't work with big data #54

Closed
andyngdz opened this issue Aug 3, 2019 · 18 comments
Closed

Doesn't work with big data #54

andyngdz opened this issue Aug 3, 2019 · 18 comments
Labels
bug Something isn't working

Comments

@andyngdz
Copy link

andyngdz commented Aug 3, 2019

Currently,
I'm fetching the data from this API (https://api.coincap.io/v2/assets/bitcoin/history?interval=d1)

I created a FlSpot with these values:
FlSpot(2757.4283650019844275, 1501718400000.1)

The chart doesn't work and the app stops working as well.

@andy1xx8
Copy link

andy1xx8 commented Aug 3, 2019

I'm having the same issue too.
It doesn't work with a big value.

@sukhcha-in
Copy link

@andynguy3n @tauitdnmd I was having similar issue, when large data is passed app becomes unresponsive and might crash too.
Instead of passing values directly to chart calculate the percentage of each value between 0-100 then use it in fl_chart.

@Dhuliang
Copy link

Same issue

@imaNNeo imaNNeo added the bug Something isn't working label Aug 15, 2019
@imaNNeo
Copy link
Owner

imaNNeo commented Aug 20, 2019

Sore for delay, I've tried with the values that you said:

And it works just fine!

May I ask you use the latest version of fl_chart, and check it again?

@imaNNeo
Copy link
Owner

imaNNeo commented Aug 23, 2019

It's gonna be closed if I don't get any answer in a day because I tested it and it works in new versions.

@andyngdz
Copy link
Author

Thanks @imaNNeoFighT ,
I'll test it again soon.

@imaNNeo
Copy link
Owner

imaNNeo commented Aug 29, 2019

Unfortunately, I'm gonna close it soon

@andyngdz
Copy link
Author

andyngdz commented Sep 20, 2019

Hi @imaNNeoFighT

I think with this number it doesn't work
1506124800000.0

Since the Unix timestamp is int, I covert to double by using this function

  List<FlSpot> listSpots() => this.data.map((assetData) {
        return FlSpot(
          assetData.time.roundToDouble(),
          double.parse(assetData.priceUsd),
        );
      }).toList();

Then try with 5 items

  @override
  Widget build(BuildContext context) {
    return FlChart(
      chart: LineChart(
        LineChartData(
          lineBarsData: [
            LineChartBarData(
                spots: listSpots().take(5).toList(),
                isCurved: true,
                isStrokeCapRound: false)
          ],
        ),
      ),
    );
  }

Screen Shot 2019-09-20 at 10 10 36 PM

@imaNNeo
Copy link
Owner

imaNNeo commented Sep 27, 2019

Hi guys, I know your problem, but not sure what could we do,
I think you guys can scale down your values to fix this problem, is it works?

@andyngdz
Copy link
Author

Thanks. I'll try. Have a good day.

@18601673727
Copy link

For minY: 70833.02 and maxY: 116880.3, I have this chart with 12 dots, x ranges from 1 to 12, render with LineChart got result like this:
截屏2022-03-07 上午5 04 36
@imaNNeoFighT Please help...

@imaNNeo
Copy link
Owner

imaNNeo commented Mar 6, 2022

Hi @18601673727
What's the problem?

@18601673727
Copy link

Hi @18601673727 What's the problem?

The line just looks too art-y don't you think sir?

@imaNNeo
Copy link
Owner

imaNNeo commented Mar 6, 2022

Sorry I didn't understand.

@18601673727
Copy link

Sorry I didn't understand.

I mean I'm expecting the line to be still "singe-directioned" not twisted when y value of the dots get greater than certain value or by any other circumstances.

@imaNNeo
Copy link
Owner

imaNNeo commented Mar 7, 2022

Can you give me your simplified code to reproduce?

@andyngdz andyngdz changed the title Doesnt' work with big data Doesn't work with big data Mar 8, 2022
@RodolfoSilva
Copy link

RodolfoSilva commented Apr 24, 2022

I think you can use this class to help you scale the values to keep the number inside the range configured to fl_chart.

class ScaleLinear {
  ScaleLinear({
    required this.domainMin,
    required this.domainMax,
    required this.rangeMin,
    required this.rangeMax,
  })  : targetRange = rangeMax - rangeMin,
        domainRange = domainMax - domainMin;

  final num targetRange;
  final num domainRange;
  final num domainMin;
  final num domainMax;
  final num rangeMin;
  final num rangeMax;

  double calc(num value) {
    return (value - domainMin) * targetRange / domainRange + rangeMin;
  }

  double invert(num value) {
    return (value - rangeMin) * domainRange / targetRange + domainMin;
  }
}


void main() {
  final y = ScaleLinear(
    domainMin: 4500,
    domainMax: 10000,
    rangeMin: 1,
    rangeMax: 10,
  );

  print(y.calc(10000)); // 10
  print(y.calc(8000)); // 6.7272727272727275
  print(y.calc(4500)); // 1
  // Invert
  print(y.invert(10)); // 10000
  print(y.invert(6.7272727272727275)); // 8000
  print(y.invert(1)); // 4500
}

@catteneo
Copy link

catteneo commented May 10, 2022

Hi guys, I know your problem, but not sure what could we do, I think you guys can scale down your values to fix this problem, is it works?

Could you elaborate on what exactly is this problem?
Stumbled upon it, and had to use some scaling strategy too

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

8 participants