Comments (2)
class LineChartSample10 extends StatefulWidget {
const LineChartSample10({super.key});
final Color sinColor = AppColors.contentColorBlue;
final Color cosColor = AppColors.contentColorPink;
@OverRide
State createState() => _LineChartSample10State();
}
class _LineChartSample10State extends State {
final limitCount = 2000;
final sinPoints = [];
final cosPoints = [];
double xValue = 0;
double step = 0.05;
late Timer timer;
@OverRide
void initState() {
super.initState();
timer = Timer.periodic(const Duration(milliseconds: 100), (timer) {
double vectorResult = Random().nextInt(100).toDouble();
while (sinPoints.length > limitCount) {
sinPoints.removeAt(0);
cosPoints.removeAt(0);
}
setState(() {
sinPoints.add(FlSpot(xValue, vectorResult));
cosPoints.add(FlSpot(xValue, vectorResult));
print(sinPoints.length);
});
xValue += step;
});
}
@OverRide
Widget build(BuildContext context) {
return cosPoints.isNotEmpty
? Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const SizedBox(height: 12),
Text(
'x: ${xValue.toStringAsFixed(1)}',
style: const TextStyle(
color: AppColors.mainTextColor2,
fontSize: 18,
fontWeight: FontWeight.bold,
),
),
Text(
'sin: ${sinPoints.last.y.toStringAsFixed(1)}',
style: TextStyle(
color: widget.sinColor,
fontSize: 18,
fontWeight: FontWeight.bold,
),
),
Text(
'cos: ${cosPoints.last.y.toStringAsFixed(1)}',
style: TextStyle(
color: widget.cosColor,
fontSize: 18,
fontWeight: FontWeight.bold,
),
),
const SizedBox(
height: 12,
),
AspectRatio(
aspectRatio: 1.5,
child: Padding(
padding: const EdgeInsets.only(bottom: 24.0),
child: LineChart(
duration: Duration.zero,//확인 완료
LineChartData(
minY: -1,
maxY: 100,
minX: sinPoints.first.x,
maxX: sinPoints.last.x,
lineTouchData: const LineTouchData(enabled: true),//변경
clipData: const FlClipData.all(),
gridData: const FlGridData(
show: true,
drawVerticalLine: false,
),
borderData: FlBorderData(show: true),//변경
lineBarsData: [
sinLine(sinPoints),
//cosLine(cosPoints),
],
titlesData: const FlTitlesData(
show: true,
),
),
),
),
)
],
)
: Container();
}
LineChartBarData sinLine(List points) {
return LineChartBarData(
spots: points,
dotData: const FlDotData(
show: false,
),
gradient: LinearGradient(
//colors: [widget.sinColor.withOpacity(0), widget.sinColor],
colors: [widget.sinColor.withOpacity(0), widget.sinColor],
stops: const [0, 0],//변경
),
barWidth: 4,
isCurved: true,//변경
);
}
LineChartBarData cosLine(List points) {
return LineChartBarData(
spots: points,
dotData: const FlDotData(
show: true,
),
gradient: LinearGradient(
colors: [widget.cosColor.withOpacity(0), widget.cosColor],
stops: const [0.1, 1.0],
),
barWidth: 4,
isCurved: false,
);
}
@OverRide
void dispose() {
timer.cancel();
super.dispose();
}
}
from fl_chart.
Please provide a reproducible code (a main.dart file content)
from fl_chart.
Related Issues (20)
- Draw a order around each sector HOT 1
- Exception: indicatorsData and touchedSpotOffsets size should be same. need help pls. HOT 2
- Ability to set different colors for parts of the line from a line chart HOT 1
- What is best way for make slider change y axis with fl_chart HOT 1
- Side titles are not placed the same way when values are translated
- How to customize LineTooltipItem
- NullSpot's isNull broken when using copyWith HOT 1
- Discrepancy in documentation
- Specify GraphArea height for barChart
- [Feature Request] Ability to replace LineTouchTooltipData widget HOT 5
- Programmatically display the tooltip for a given X value HOT 2
- I need to get offset extraLines of BarChart when touch it HOT 1
- How can I set the bottom title with the date and interval by time? HOT 2
- PieChart centerSpace disapearing HOT 3
- I can't find how to disable linechart's default animation. HOT 2
- Is the interval of SideTitles invalid for BarChart?
- Line Chart tooltip on only certain lines HOT 6
- Thorny LineChart HOT 5
- Is there a provision to change size of FlSpot? HOT 1
- TouchedSpotIndicator duplicates when updating 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 fl_chart.