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

set x and y axis values ordered #32

Closed
nasr25 opened this issue Apr 27, 2019 · 3 comments
Closed

set x and y axis values ordered #32

nasr25 opened this issue Apr 27, 2019 · 3 comments
Labels
question Further information is requested

Comments

@nasr25
Copy link

nasr25 commented Apr 27, 2019

Hi

i have example code to show line chart, but X and Y axis values not ordered, how can i make it ordered from 0 to big number in series.

`class SimpleLineChart extends StatelessWidget {
// X value -> Y value
static const myData = [
[2,5],
[1,3],
[10,9],
];

@OverRide
Widget build(BuildContext context) {
return new LineChart(
lines: [
new Line<List, String, String>(
data: myData,
xFn: (datum) => datum[0],
yFn: (datum) => datum[1],
),
],
chartPadding: new EdgeInsets.fromLTRB(30.0, 10.0, 10.0, 30.0),
);
}
}`

@nasr25
Copy link
Author

nasr25 commented Apr 28, 2019

No answer ???

@thekeenant
Copy link
Owner

Hi, it's just me on this project so there isn't much support.

You can sort the data before providing it to the line chart. This sorts your data by the X axis value ascending:

final sortedData = <List<int>>[]..addAll(myData)..sort((a, b) {
  return a.first.compareTo(b.first);
});

@thekeenant thekeenant added the question Further information is requested label Apr 28, 2019
@nasr25
Copy link
Author

nasr25 commented Apr 28, 2019

Ok, thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants