Code Monkey home page Code Monkey logo

Comments (2)

chaeni332 avatar chaeni332 commented on May 25, 2024

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.

imaNNeo avatar imaNNeo commented on May 25, 2024

Please provide a reproducible code (a main.dart file content)

from fl_chart.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.