ace_chart
两年前做的股票项目,用了一些开源的插件有些数据卡顿,有些滚动卡顿,参考了几个开源的库,具体名字忘了哪些。。股票K线图/分时图/vol图/mac的图/双极图,在币圈的行情下使用的话,有些地方需要修改。已发不到pub.dev pub.dev/packages/ac...
Screenshot
Demo
dart
import 'dart:async';
import 'package:ace_chart/ace_chart.dart';
import 'package:demo/data.dart'; // 数据list,文章字数有限制,请从github获取
import 'package:demo/data2.dart'; // 数据list2,,文章字数有限制,请从github获取
import 'package:flutter/material.dart';
const Color backgroundColor = Color(0xff151924);
const Color textColor = Colors.white;
const TextStyle style = TextStyle(color: textColor);
class Home extends StatefulWidget {
const Home({super.key});
@override
State<Home> createState() => _HomeState();
}
int ii = 0;
class _HomeState extends State<Home> {
final AceStockMetricController container = AceStockMetricController(
useVOLMA: true,
useMACD: true,
maxLength: list.length,
// maDays: [5],
pointWidth: 7,
useKdj: true,
);
final AceStockMetricController container3 = AceStockMetricController(
useVOLMA: true,
useMACD: true,
maxLength: list2.length,
maDays: [],
useKdj: true,
);
@override
void initState() {
super.initState();
int i = 60;
container.addAll(list.sublist(0, i));
Timer.periodic(const Duration(milliseconds: 10), (timer) {
if (i < list.length) {
container.addValue(list[i]);
} else {
timer.cancel();
}
i++;
});
Timer.periodic(const Duration(milliseconds: 10), (timer) {
if (ii < list2.length) {
container3.addValue(list2[ii]);
} else {
timer.cancel();
}
ii++;
setState(() {});
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text(
"DEMO",
style: style,
),
backgroundColor: backgroundColor,
),
backgroundColor: backgroundColor,
body: SingleChildScrollView(
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
AceContainer(
controller: container3,
child: Builder(
builder: (context) {
return Column(
children: [
SizedBox(
height: 150,
child: LineChart(
transformTime: (time) {
return millisToHM(time);
},
lineColor: const Color(0xff697abc),
lastClose: 255.90,
gridVerticalGrids: 1,
gridHorizontalGrids: 2,
paddingTop: 20,
centralAxisStyle: const TextStyle(
color: Colors.white,
fontSize: 8,
),
gridLineColor: Colors.white12,
crossLineColor: const Color(0xffd13e51),
crossTextBgColor: const Color(0xffd13e51),
horizontalTextStyle: const TextStyle(
color: Color(0xff959FAE),
fontSize: 8,
),
),
),
Container(
height: 10,
color: Colors.black,
),
const SizedBox(
height: 40,
child: VolChart(
showMaLine: true,
showText: false,
upperStyle: PaintingStyle.stroke,
),
),
Container(
height: 10,
color: Colors.black,
),
const SizedBox(
height: 80,
child: MacdChart(
textStyle: TextStyle(
color: Colors.white,
fontSize: 8,
),
),
),
],
);
},
),
),
Container(
height: 10,
margin: const EdgeInsets.symmetric(vertical: 3),
color: Colors.black,
),
Container(
color: Colors.black12,
child: AceContainer(
controller: container,
child: Builder(
builder: (context) {
return Column(
children: [
SizedBox(
height: 150,
child: KChart(
highMarkColor: Colors.white,
lowMarkColor: Colors.white,
crossLineColor: const Color(0xffd13e51),
crossTextBgColor: const Color(0xffd13e51),
gridTextStyle: const TextStyle(
color: Colors.white,
fontSize: 8,
),
gridLineColor: Colors.white12,
horizontalTextStyle: const TextStyle(
color: Color(0xff959FAE),
fontSize: 8,
),
transformTime: (time) {
return millisToMD(time);
},
onCrossChange: (index, alignment) {
if (index == -1) {
return;
}
},
),
),
Container(
height: 10,
margin: const EdgeInsets.symmetric(vertical: 3),
color: Colors.black,
),
const SizedBox(
height: 40,
child: VolChart(
showMaLine: true,
showText: false,
upperStyle: PaintingStyle.stroke,
textStyle: TextStyle(
color: Colors.white,
fontSize: 8,
),
),
),
Container(
height: 10,
margin: const EdgeInsets.symmetric(vertical: 3),
color: Colors.black,
),
const SizedBox(
height: 80,
child: MacdChart(
textStyle: TextStyle(
color: Colors.white,
fontSize: 8,
),
),
),
Container(
height: 10,
margin: const EdgeInsets.symmetric(vertical: 3),
color: Colors.black,
),
Padding(
padding: const EdgeInsets.all(20),
child: SizedBox(
height: 199,
width: 199,
child: CircularProgressIndicator(
value: (ii + 1) / list2.length,
strokeWidth: 10,
color: const Color(0xff9096FF),
backgroundColor: Colors.white54,
),
),
),
],
);
},
),
),
),
const SizedBox(
height: 10,
),
],
),
),
);
}
}