Comments (2)
import 'package:flutter/material.dart';
import 'package:graphic/graphic.dart';
import 'dart:async';
class LineAreaPointPage extends StatefulWidget {
const LineAreaPointPage({Key? key}) : super(key: key);
@override
LineAreaPointPageState createState() => LineAreaPointPageState();
}
class LineAreaPointPageState extends State<LineAreaPointPage> {
int _counter = 0;
late Timer _timer;
List<Map> _invalidDateUser = [];
final GlobalKey<ScaffoldState> _scaffoldKey = GlobalKey<ScaffoldState>();
@override
void initState() {
_invalidDateUser = [
{"Date": "790085", "Close": 10},
{"Date": "790086", "Close": 11},
{"Date": "790087", "Close": 12},
];
_timer = Timer.periodic(const Duration(seconds: 1), (_) {
setState(() {
_counter++;
// _invalidDateUser = [
// {"Date": "790085", "Close": _counter + 10},
// {"Date": "790086", "Close": _counter + 11},
// {"Date": "790087", "Close": _counter + 12},
// ];
_invalidDateUser.add(
{"Date": DateTime.now().microsecond.toString(), "Close": _counter});
});
});
super.initState();
}
@override
void dispose() {
_timer.cancel();
super.dispose();
}
@override
Widget build(BuildContext context) {
print("Rebuild.");
return Scaffold(
key: _scaffoldKey,
appBar: AppBar(
title: const Text('Line and Area Mark'),
),
backgroundColor: Colors.white,
body: SingleChildScrollView(
child: Center(
child: Column(children: <Widget>[
Container(
//测试用图标
padding: const EdgeInsets.fromLTRB(20, 40, 20, 5),
child: const Text(
'User Test Chart',
style: TextStyle(fontSize: 20),
),
),
Container(
margin: const EdgeInsets.only(top: 10),
width: 400,
height: 350,
child: Chart(
// rebuild: false,
data: _invalidDateUser,
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,
),
},
marks: [
LineMark(
shape: ShapeEncode(value: BasicLineShape(smooth: false)),
size: SizeEncode(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]), //指示选中点的样式
coord: RectCoord(
horizontalRange: [0, 0.95],
verticalRange: [0.05, 0.95],
horizontalRangeUpdater: Defaults.horizontalRangeEvent,
verticalRangeUpdater: Defaults.verticalRangeEvent,
),
),
),
]))));
}
}
from graphic.
出于性能的考虑,图表只有在 data 变成新数组时更新,而不会检测数组内部的变化。list.add 不会产生新数组,改成:
_invalidDateUser = [..._invalidDateUser, {"Date": DateTime.now().microsecond.toString(), "Close": _counter}];
from graphic.
Related Issues (20)
- Take a look at my design!
- 对数坐标
- [BUG] Pinch zoom gesture causes an exception
- Error in TooltipRenderOp.render when a NaN value is selected
- Candlechart does not render circuit data points as it has same ohlc for that particular candle.
- Is it possible to Scroll only the barchart data and x axis without scrolling the y axis
- Add button to tooltip
- Mark transition and selections doesn't work well together.
- Question: How to create this chart
- horizontalRangeUpdater 如何实现滚动到第一个坐标就截止,最后一个坐标也截止 HOT 1
- Is is possible to put a label to a graph axis? HOT 2
- Communicating with other widgets HOT 1
- Tool tip not working on iOS HOT 2
- 如何滑动到指定坐标点?
- 如何获取可视区域内的所有坐标点? HOT 1
- 如何给 X 轴的首尾添加箭头?
- Questions whether few things are possible
- marginMin、marginMax 设置为 0,会导致第一个和最后一个 Mark 的宽度只有一半
- Y轴的数值很长,会超出 Chart 显示区域范围
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from graphic.