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

处理大量数据的时候非常卡顿,是有什么操作秘诀我不会么? #59

Closed
codepgq opened this issue Mar 5, 2022 · 1 comment

Comments

@codepgq
Copy link

codepgq commented Mar 5, 2022

Chart(
                      data: lineData,
                      variables: {
                        'Date': Variable(
                          accessor: (Map map) => map['Date'] as String,
                          scale: OrdinalScale(tickCount: 5),
                        ),
                        'Close': Variable(
                          accessor: (Map map) =>
                          (map['Close'] ?? double.nan) as num,
                        ),
                      },
                      elements: [
                        AreaElement(
                          shape: ShapeAttr(value: BasicAreaShape(smooth: true)),
                          color: ColorAttr(
                              value: Defaults.colors10.first.withAlpha(80)),
                        ),
                        LineElement(
                          shape: ShapeAttr(value: BasicLineShape(smooth: true)),
                          size: SizeAttr(value: 0.5),
                        ),
                      ],
                      axes: [
                        Defaults.horizontalAxis,
                        Defaults.verticalAxis,
                      ],
                      selections: {
                        'touchMove': PointSelection(
                          on: {
                            GestureType.scaleUpdate,
                            GestureType.tapDown,
                            GestureType.longPressMoveUpdate
                          },
                          dim: Dim.x,
                        )
                      },
                      tooltip: TooltipGuide(
                        followPointer: [false, true],
                        align: Alignment.topLeft,
                        offset: const Offset(-20, -20),
                      ),
                      crosshair: CrosshairGuide(followPointer: [false, true]),
                    )

下面是数据源

final lineData = <Map<String, dynamic>>[];// {"Date": "04.01.2016", "Close": 126.12};
configLineData() {
  final now = DateTime.now();
  final random = Random();
  for (int i = 0; i<40000; i++) {
    final time = now.subtract(Duration(minutes: i));
    final timeStr = "${time.year}-${time.month.toString().padLeft(2,'0')}-${time.day.toString().padLeft(2,'0')} ${time.hour.toString().padLeft(2,'0')}:${time.minute.toString().padLeft(2,'0')}:00";
    lineData.add({"Date": timeStr, "Close": random.nextDouble() * 20 + 70});
  }
}
@dJani97
Copy link

dJani97 commented Mar 7, 2022

It seems to me that you're generating all that data synchronously during the build method. Try doing it asynchronously and use something like a FutureBuilder to only show the chart once you have the adata generated.

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

No branches or pull requests

3 participants