Finding data on line chart (SwiftCharts) - swift

I created a line chart using SwiftCharts. Now I am trying to find the data on the chart. User gonna input numbers, which meets x any y axis and swift should mark the intersection of these two and tell the user where their data on the line chart is. Is it above these lines if yes, above from which and below from which one as a pop up or on a text.
Thank you...
#IBAction func displayChart(_ sender: Any) {
let chartConfig = ChartConfigXY(
xAxisConfig: ChartAxisConfig(from: 0, to:192 , by: 24),
yAxisConfig: ChartAxisConfig(from: 0, to: 22, by: 1)
)
let frame = CGRect(x: 10, y: 100, width: self.view.frame.width-50, height: 550)
let chart = LineChart(frame: frame, chartConfig: chartConfig, xTitle: "Postnatal Age Hours", yTitle: "Total Bilirubin mg/dl" ,
lines: [
(chartPoints:[(0, 4.0), (12, 6.0), (24, 8.0), (36, 9.5), (48, 11.0), (60, 12.5), (72, 13.5), (84, 14.0), (96, 14.5), (108, 14.9), (120, 15.0), (132, 15.0), (144, 15.0), (156, 15.0), (168, 15.0)], color: UIColor.red),
(chartPoints:[(0, 5.0), (12, 7.5), (24, 10.0), (36, 11.8), (48, 13.0), (60, 14.5), (72, 15.1), (84, 16.4), (96, 17.1), (108, 18.0), (120, 18.0), (120, 18.0), (132, 18.0), (144, 18.0), (156, 18.0), (168, 18.0)], color : UIColor.blue),
(chartPoints:[(0, 6.5), (12, 9.0), (24, 11.5), (36, 13.5), (48, 15.0), (60, 16.5), (72, 17.5), (84, 19.0), (96, 20.0), (108, 20.5), (120, 21.0), (132, 21.0), (144, 21.0), (156, 21.0), (168, 21.0)], color: UIColor.green)
])
self.view.addSubview(chart.view)
self.pttChartView = chart
}

Related

How to play Gif file on png file?

Stack([
Image.asset(
"assets/Icon/Checkbox.png",
color: uncheckedColor,
height: 22,
width: 22,
),
Image.asset(
"assets/Icon/fullyComplete1.gif",
color: uncheckedColor,
scale: 2.5,
opacity: const AlwaysStoppedAnimation<double>(1.0),
height: 22,
width: 22,
gaplessPlayback: true,
)
])
I want play GIF file for 1 or 2 seconds then I have to show png file.
How can I achieve it?
You can, this solution is simple :
Add new variable in top class var show = false;
after that's add this function :
#override
void initState() {
Future.delayed(const Duration(seconds: 2), () {
setState(() => show = true);
});
super.initState();
}
Now add this your code
Stack([
show ? Image.asset(
"assets/Icon/Checkbox.png",
color: uncheckedColor,
height: 22,
width: 22,
) :
Image.asset(
"assets/Icon/fullyComplete1.gif",
color: uncheckedColor,
scale: 2.5,
opacity: const AlwaysStoppedAnimation<double>(1.0),
height: 22,
width: 22,
gaplessPlayback: true,
)
])

flutter - percent indicator progressColor

i use percent_indicator package. I wrapped CircularPercentIndicator with Gesturedetetor, i increase start parameter every touch onTap function.
Every time I tap to increase the numeric value by one, the CircularPercentIndicator color starts over. For example; My start parameter is 8 and once I touched it, my start parameter is 9, but the CircularPercentIndicator starts from 0 to 9.
int start = 0;
GestureDetector(
child: CircularPercentIndicator(
radius: 100.0,
lineWidth: 13.0,
animation: true,
percent: start.toDouble() / 100,
center: Text(
start.toString(),
style: const TextStyle(fontWeight: FontWeight.bold, fontSize: 20.0),
),
footer: const Text(
"Sales this week",
style: TextStyle(fontWeight: FontWeight.bold, fontSize: 17.0),
),
circularStrokeCap: CircularStrokeCap.round,
progressColor: Colors.purple,
),
onTap: () {
start = start + 1;
setState(() {});
print(start.toString());
},
),
If you check the plugin source code, that is how the plugin is developed, it updates the progress, and runs the _animation.forward(), which will make the animation start from 0 - currentProgress.
I found the solution. There is a property like below.
animateFromLastPercent: true

Flutter reduce padding of text in SleekCircularSlider

flutter reduces padding SleekCircularSlider and text. It's sowing too much space between bar and text.
my code
SleekCircularSlider(
min: 0,
max: 120.0,
initialValue: 60,
appearance: CircularSliderAppearance(
startAngle: 110,
angleRange: 70,
animationEnabled: true,
infoProperties: InfoProperties(
bottomLabelText: 'kg',
bottomLabelStyle: TextStyle(
fontSize: 20,
),
mainLabelStyle: TextStyle(
fontSize: 25,
fontFamily: 'RalewaySemiBold',
),
modifier: (double value) {
final roundedValue = value.ceil().toInt().toString();
return '$roundedValue ';
},
),
customColors: CustomSliderColors(
hideShadow: true,
trackColor: Color(0xffCFE7FB),
dotColor: Color(0XFFFAFAFA),
progressBarColor: kPrimaryColor,
),
customWidths: CustomSliderWidths(
trackWidth: 4,
progressBarWidth: 12,
handlerSize: 3,
)
),
onChangeEnd: (double weight){
return weight;
},
),
Look like this
I need to reduce the gap between bar and text.
You can use the size parameter on the CircularSliderAppearance to control how much width and height is allotted to your SleekCircularSlider widget.
For example, I added,
appearance: CircularSliderAppearance(
size: 100, // Added this
startAngle: 110,
and the output is this,
Play around and check what size suits you best. :)

Flutter: Syncfusion Chart Give Upper Limit to y-axis

I have a SfCartesianChart which displays a line chart of a list of values from 0 to 100, i.e. percentages. However, when there is a data point, for example, 99%, the upper limit of the y-axis seems like 120% which does not mean anything.
Here is my chart code
SfCartesianChart(
margin: EdgeInsets.all(0),
borderWidth: 0,
plotAreaBorderWidth: 0,
title: ChartTitle(text: 'Mood Tracks', textStyle: TextStyle(fontWeight: FontWeight.bold)),
tooltipBehavior: _tooltipBehavior,
series: <ChartSeries>[
LineSeries<MoodRecord, dynamic>(
name: 'Moods',
color: Colors.green[400],
dataSource: records,
xValueMapper: (MoodRecord record, _) => record.date,
yValueMapper: (MoodRecord record, _) => record.mood.toInt(),
dataLabelSettings: DataLabelSettings(isVisible: false),
enableTooltip: true,
animationDuration: 2000,
markerSettings: MarkerSettings(
isVisible: true,
shape: DataMarkerType.circle,
color: kPrimaryColor
)
)
],
primaryXAxis: CategoryAxis(
labelPlacement: LabelPlacement.onTicks,
labelStyle: TextStyle(fontWeight: FontWeight.bold)
),
primaryYAxis: NumericAxis(
labelFormat: '{value}%',
labelStyle: TextStyle(fontWeight: FontWeight.bold)
),
),
Is there any way to define an upper limit on the y-axis? I do not want my chart to display something like 120% on the y-axis.
If there any better way to display percentages, it would also be appreciated.
We have looked over the question and code and can inform you that the axis range is determined by the data source values. If you don't want values above 100 to be shown, use the maximum property in the axis and manually customize the range. For more details, see the help document. You may also use the numberFormat property to reflect percentage values, as seen in the example below.
https://www.syncfusion.com/kb/11519/how-to-apply-the-currency-format-to-the-axis-labels-sfcartesianchart
For 100 percent stacked charts, refer to the support document, which converts the given data to 100 percent.
SfCartesianChart(
primaryXAxis: CategoryAxis(labelStyle: const TextStyle(
color: Colors.white,
fontFamily: 'Roboto',
fontSize: 10,
)),
primaryYAxis: NumericAxis(
**minimum: 0, maximum: 100, interval: 25,**
labelFormat: '{value}%',
labelStyle: const TextStyle(
color: Colors.white,
fontFamily: 'Roboto',
fontSize: 10,
)),

How to capitalize text in Flutter

I tried to find how capitalize text in Flutter, but I couldn't find it.
My code:
Center(
heightFactor: 2,
child: Text(
'Strengthening the bond of owners and pets, more than ever...',
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 20.0,
fontStyle: FontStyle.italic,
fontWeight: FontWeight.bold,
color: Colors.cyanAccent[700],
wordSpacing: 8,
),
)),
I dont know if there is a way to do it through the Text widget, but you can use string.toUppercase() to capitalize the word:
Center(
heightFactor: 2,
child: Text(
'Strengthening the bond of owners and pets, more than ever...'.toUpperCase(),
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 20.0,
fontStyle: FontStyle.italic,
fontWeight: FontWeight.bold,
color: Colors.cyanAccent[700],
wordSpacing: 8,
),
)),
To capitalize and to uppercase are different:
Capitalize: "Strengthing..."
Uppercase: "STRENGTHING..."
Capitalize
To capitalize a string in all locales:
import 'package:intl/intl.dart';
toBeginningOfSentenceCase('strengthening...');
To capitalize a string for en-US like locales:
String text = 'strengthening...';
text = text[0].toUpperCase() + text.substring(1).toLowerCase();
You can also have the virtual keyboard automatically switch to uppercase on the start of a sentence:
TextField(
textCapitalization: TextCapitalization.sentences
)
https://api.flutter.dev/flutter/services/TextCapitalization.html
Uppercase
To uppercase a string:
'strengthening...'.toUpperCase()
You can also have the virtual keyboard automatically switch to uppercase on each character
TextField(
textCapitalization: TextCapitalization.characters
)
https://api.flutter.dev/flutter/services/TextCapitalization.html
Better way to capitalize text
// copy this code to somewhere in your dart file
// also you can write/add methods to below code to support your strings to modify i.e. `toCapitalize()` or `yourStringModifyingMethod`.
extension StringCasingExtension on String {
String toCapitalize() => length > 0 ? ${this[0].toUpperCase()}${substring(1).toLowerCase()}' : '';
// String yourStringModifyingMethod() => write your logic here to modify the string as per your need;
}
Here is how you can use it
var word = 'this is capital'.toCapitalized(); // 'This is capital'
Well, you could use this package to capitalize the content in the Text widget:
https://pub.dev/packages/text_tools.
//This will put the letter in position 15 in UpperCase, will print 'Strengthening The bond of owners and pets, more than ever...'
Center(
heightFactor: 2,
child: Text(
TextTools.toUppercaseAnyLetter(text: 'Strengthening the bond of owners and pets, more than ever...', position: 15),
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 20.0,
fontStyle: FontStyle.italic,
fontWeight: FontWeight.bold,
color: Colors.cyanAccent[700],
wordSpacing: 8,
),
)),