This is my app.js file
var earn=[' ',' ',' ',' ',' '];
var lost=['50','60','100','40','20'];
var Break=['40','30','90','90','40'];
var win = Titanium.UI.createWindow({
backgroundColor: 'white'
});
var lbl1 = Ti.UI.createLabel({
backgroundColor: '#CED8F6',
height:'5%',
width:'10%',
top:0,
left:0,
borderWidth: 2,
borderColor: 'black',
});
var lbl2 = Ti.UI.createLabel({
backgroundColor: 'white',
text:'Earn',
height:'5%',
width:'10%',
top:'5%',
left:0,
color: 'black',
borderWidth: 2,
borderColor: 'black',
textAlign: Titanium.UI.TEXT_ALIGNMENT_CENTER,
});
win.add(lbl2);
var lbl3 = Ti.UI.createLabel({
backgroundColor: '#CED8F6',
text:'Lost',
height:'5%',
width:'10%',
top:'10%',
left:0,
color: 'black',
borderWidth: 2,
borderColor: 'black',
textAlign: Titanium.UI.TEXT_ALIGNMENT_CENTER,
});
win.add(lbl3);
var lbl4 = Ti.UI.createLabel({
backgroundColor: 'white',
text:'Break',
height:'5%',
width:'10%',
top:'15%',
left:0,
color: 'black',
borderWidth: 2,
borderColor: 'black',
textAlign: Titanium.UI.TEXT_ALIGNMENT_CENTER,
});
win.add(lbl4);
var lbl5 = Ti.UI.createLabel({
backgroundColor: 'white',
text:'Jan',
height:'5%',
width:'10%',
top:0,
left:'10%',
color: 'black',
borderWidth: 2,
borderColor: 'black',
textAlign: Titanium.UI.TEXT_ALIGNMENT_CENTER,
});
win.add(lbl5);
var textfield1 = Ti.UI.createTextField({
backgroundColor: '#CED8F6',
value:earn[0],
height:'5%',
width:'10%',
top:'5%',
left:'10%',
color: 'black',
borderWidth: 1,
borderColor: 'black',
keyboardType: Titanium.UI.KEYBOARD_NUMBER_PAD,
textAlign: Titanium.UI.TEXT_ALIGNMENT_CENTER,
});
win.add(textfield1);
var lbl7 = Ti.UI.createLabel({
backgroundColor: 'white',
text:lost[0],
height:'5%',
width:'10%',
top:'10%',
left:'10%',
color: 'black',
borderWidth: 1,
borderColor: 'black',
textAlign: Titanium.UI.TEXT_ALIGNMENT_CENTER,
});
win.add(lbl7);
var lbl8 = Ti.UI.createLabel({
backgroundColor: '#CED8F6',
text:Break[0],
height:'5%',
width:'10%',
top:'15%',
left:'10%',
color: 'black',
borderWidth: 1,
borderColor: 'black',
textAlign: Titanium.UI.TEXT_ALIGNMENT_CENTER,
});
win.add(lbl8);
var lbl9 = Ti.UI.createLabel({
text:'Feb',
backgroundColor: '#CED8F6',
height:'5%',
width:'10%',
left:'20%',
top:'0%',
color:'black',
borderWidth: 2,
borderColor: 'black',
textAlign: Titanium.UI.TEXT_ALIGNMENT_CENTER,
});
win.add(lbl9);
var textfield2 = Ti.UI.createTextField({
backgroundColor: 'white',
value:earn[1],
height:'5%',
width:'10%',
top:'5%',
left:'20%',
color: 'black',
borderWidth: 1,
borderColor: 'black',
keyboardType: Titanium.UI.KEYBOARD_NUMBER_PAD,
textAlign: Titanium.UI.TEXT_ALIGNMENT_CENTER,
});
win.add(textfield2);
var lbl11 = Ti.UI.createLabel({
backgroundColor: '#CED8F6',
text:lost[1],
height:'5%',
width:'10%',
top:'10%',
left:'20%',
color: 'black',
borderWidth: 1,
borderColor: 'black',
textAlign: Titanium.UI.TEXT_ALIGNMENT_CENTER,
});
win.add(lbl11);
var lbl12 = Ti.UI.createLabel({
backgroundColor: 'white',
text:Break[1],
height:'5%',
width:'10%',
top:'15%',
left:'20%',
color: 'black',
borderWidth: 1,
borderColor: 'black',
textAlign: Titanium.UI.TEXT_ALIGNMENT_CENTER,
});
win.add(lbl12);
var lbl13 = Ti.UI.createLabel({
backgroundColor: 'white',
text:'March',
height:'5%',
width:'10%',
top:0,
left:'30%',
color: 'black',
borderWidth: 2,
borderColor: 'black',
textAlign: Titanium.UI.TEXT_ALIGNMENT_CENTER,
});
win.add(lbl13);
var textfield3 = Ti.UI.createTextField({
backgroundColor: '#CED8F6',
value:earn[2],
height:'5%',
width:'10%',
top:'5%',
left:'30%',
color: 'black',
borderWidth: 1,
borderColor: 'black',
keyboardType: Titanium.UI.KEYBOARD_NUMBER_PAD,
textAlign: Titanium.UI.TEXT_ALIGNMENT_CENTER,
});
win.add(textfield3);
var lbl15 = Ti.UI.createLabel({
backgroundColor: 'white',
text:lost[2],
height:'5%',
width:'10%',
top:'10%',
left:'30%',
color: 'black',
borderWidth: 1,
borderColor: 'black',
textAlign: Titanium.UI.TEXT_ALIGNMENT_CENTER,
});
win.add(lbl15);
var lbl16 = Ti.UI.createLabel({
backgroundColor: '#CED8F6',
text:Break[2],
height:'5%',
width:'10%',
top:'15%',
left:'30%',
color: 'black',
borderWidth: 1,
borderColor: 'black',
textAlign: Titanium.UI.TEXT_ALIGNMENT_CENTER,
});
win.add(lbl16);
var lbl17 = Ti.UI.createLabel({
text:'Apr',
backgroundColor: '#CED8F6',
height:'5%',
width:'10%',
left:'40%',
top:'0%',
color:'black',
borderWidth: 2,
borderColor: 'black',
textAlign: Titanium.UI.TEXT_ALIGNMENT_CENTER,
});
win.add(lbl17);
var textfield4 = Ti.UI.createTextField({
backgroundColor: 'white',
value:earn[3],
height:'5%',
width:'10%',
top:'5%',
left:'40%',
color: 'black',
borderWidth: 1,
borderColor: 'black',
keyboardType: Titanium.UI.KEYBOARD_NUMBER_PAD,
textAlign: Titanium.UI.TEXT_ALIGNMENT_CENTER,
});
win.add(textfield4);
var lbl19 = Ti.UI.createLabel({
backgroundColor: '#CED8F6',
text:lost[3],
height:'5%',
width:'10%',
top:'10%',
left:'40%',
color: 'black',
borderWidth: 1,
borderColor: 'black',
textAlign: Titanium.UI.TEXT_ALIGNMENT_CENTER,
});
win.add(lbl19);
var lbl20 = Ti.UI.createLabel({
backgroundColor: 'white',
text:Break[3],
height:'5%',
width:'10%',
top:'15%',
left:'40%',
color: 'black',
borderWidth: 1,
borderColor: 'black',
textAlign: Titanium.UI.TEXT_ALIGNMENT_CENTER,
});
win.add(lbl20);
var lbl21= Ti.UI.createLabel({
backgroundColor: 'white',
text:'May',
height:'5%',
width:'10%',
top:0,
left:'50%',
color: 'black',
borderWidth: 2,
borderColor: 'black',
textAlign: Titanium.UI.TEXT_ALIGNMENT_CENTER,
});
win.add(lbl21);
var textfield5 = Ti.UI.createTextField({
backgroundColor: '#CED8F6',
value:earn[4],
height:'5%',
width:'10%',
top:'5%',
left:'50%',
color: 'black',
borderWidth: 1,
borderColor: 'black',
keyboardType: Titanium.UI.KEYBOARD_NUMBER_PAD,
textAlign: Titanium.UI.TEXT_ALIGNMENT_CENTER,
});
win.add(textfield5);
var lbl23 = Ti.UI.createLabel({
backgroundColor: 'white',
text:lost[4],
height:'5%',
width:'10%',
top:'10%',
left:'50%',
color: 'black',
borderWidth: 1,
borderColor: 'black',
textAlign: Titanium.UI.TEXT_ALIGNMENT_CENTER,
});
win.add(lbl23);
var lbl24 = Ti.UI.createLabel({
backgroundColor: '#CED8F6',
text:Break[4],
height:'5%',
width:'10%',
top:'15%',
left:'50%',
color: 'black',
borderWidth: 1,
borderColor: 'black',
textAlign: Titanium.UI.TEXT_ALIGNMENT_CENTER,
});
win.add(lbl24);
var btn = Ti.UI.createButton({
title: 'Bar Chart',
bottom: '5%',
left: '2%',
width: '10%'
});
btn.addEventListener('click', function(e)
{
win.remove(layer);
win.add(webview);
});
//win.add(webview);
var btn1 = Ti.UI.createButton({
title: 'Pie Chart',
bottom: '12%',
left: '2%',
width: '10%'
});
btn1.addEventListener('click', function(e)
{
earn[0] = textfield1.value;
earn[1] = textfield2.value;
earn[2] = textfield3.value;
earn[3] = textfield4.value;
earn[4] = textfield5.value;
alert(earn[0]);
win.add(layer);
win.remove(webview);
});
var webview = Titanium.UI.createWebView({
url:'chart.html',
top: '25%',
left: '12%',
});
webview.addEventListener('beforeload',function(e)
{
earn[0] = textfield1.value;
earn[1] = textfield2.value;
earn[2] = textfield3.value;
earn[3] = textfield4.value;
earn[4] = textfield5.value;
wbv1.evalJS("var earn[0] ='"+earn[0]+"';");
wbv1.evalJS("var earn[1] ='"+earn[1]+"';");
wbv1.evalJS("var earn[2] ='"+earn[2]+"';");
wbv1.evalJS("var earn[3] ='"+earn[3]+"';");
wbv1.evalJS("var earn[4] ='"+earn[4]+"';");
});
var layer = Ti.UI.createView({
top: '25%',
left: '12%',
bottom: '0%',
});
//win.add(layer);
var wbv1 = Ti.UI.createWebView({
url:'pie1.html',
top: '0%',
left: '0%',
right:'67%',
//bottom: 0,
});
wbv1.addEventListener('afterload',function(e)
{
earn[0] = textfield1.value;
earn[1] = textfield2.value;
earn[2] = textfield3.value;
earn[3] = textfield4.value;
earn[4] = textfield5.value;
wbv1.evalJS("var earn[0] ='"+earn[0]+"';");
wbv1.evalJS("var earn[1] ='"+earn[1]+"';");
wbv1.evalJS("var earn[2] ='"+earn[2]+"';");
wbv1.evalJS("var earn[3] ='"+earn[3]+"';");
wbv1.evalJS("var earn[4] ='"+earn[4]+"';");
});
layer.add(wbv1);
var wbv2 = Ti.UI.createWebView({
url:'pie2.html',
top: '0%',
left: '33%',
right:'33%',
//bottom: 0,
});
layer.add(wbv2);
var wbv3 = Ti.UI.createWebView({
url:'pie3.html',
top: '0%',
left: '67%',
right:'0%',
//bottom: 0,
});
layer.add(wbv3);
win.add(btn1);
win.add(btn);
win.add(lbl1);
win.open();
and this is my pie1.html
<html>
<head>
<title> Earn </title>
<script language="javascript" src="http://www.google.com/jsapi"></script>
<script language="javascript" src="app.js" type="text/javascript"></script>
<meta name="viewport" content="user-scalable=0">
</head>
<body>
<div id="chart"></div>
<script type="text/javascript">
document.ontouchmove = function(event){
event.preventDefault();
}
var queryString = '';
var dataUrl = '';
function onLoadCallback() {
if (dataUrl.length > 0) {
var query = new google.visualization.Query(dataUrl);
query.setQuery(queryString);
query.send(handleQueryResponse);
} else {
var dataTable = new google.visualization.DataTable();
dataTable.addRows(5);
dataTable.addColumn('number');
dataTable.setValue(0, 0, +earn[0]);
dataTable.setValue(1, 0, +earn[1]);
dataTable.setValue(2, 0, +earn[2]);
dataTable.setValue(3, 0, +earn[3]);
dataTable.setValue(4, 0, +earn[4]);
draw(dataTable);
}
}
function draw(dataTable) {
var vis = new google.visualization.ImageChart(document.getElementById('chart'));
var options = {
chxs: '0,000000,11.5', //size of the pie
chxt: 'x',
chs: '360x265', //size of pie
cht: 'p',
chco: 'FF9900', //color of the pie
chd: 's:9flxY',
chdl: earn[0]+'|'+earn[1]+'|'+earn[2]+'|'+earn[3]+'|'+earn[4],
chl: 'Jan|Feb|March|Apr|May',
chma: '25',
chtt: 'Earn',
chts: '000000,14.5',
bottom: '0', //word size of the pie
};
vis.draw(dataTable, options);
}
function handleQueryResponse(response) {
if (response.isError()) {
alert('Error in query: ' + response.getMessage() + ' ' + response.getDetailedMessage());
return;
}
draw(response.getDataTable());
}
/* document.body.addEventListener('touchmove', function(e) {
// This prevents native scrolling from happening.
we e.preventDefault();
}, false);*/
google.load("visualization", "1", {packages:["imagechart"]});
google.setOnLoadCallback(onLoadCallback);
</script>
</body>
</html>
Im trying for my 1st pie as input data on the table and pass the array to html file so that the pie can detect the array and plot itself, but now the problem is that it is not showing the correct data i input. it will just trace the global variable as (' ') nothing instead of the one i input. Sorry for the long coding, im still new, that's the only way i know how to create a table.
I did not go through all your code (there is too much) but I did notice that you do this:
webview.addEventListener('beforeload',function(e)
{
earn[0] = textfield1.value;
earn[1] = textfield2.value;
earn[2] = textfield3.value;
earn[3] = textfield4.value;
earn[4] = textfield5.value;
wbv1.evalJS("var earn[0] ='"+earn[0]+"';");
wbv1.evalJS("var earn[1] ='"+earn[1]+"';");
wbv1.evalJS("var earn[2] ='"+earn[2]+"';");
wbv1.evalJS("var earn[3] ='"+earn[3]+"';");
wbv1.evalJS("var earn[4] ='"+earn[4]+"';");
});
You can't call evalJS on a webview till after the load event has been fired, evalJS only works if there is a page with a DOM that has been loaded first, so this wont do anything. You need to only call evalJS on a load event.
Related
I'm using this package sunmi_printer_plus.
Here my code
await SunmiPrinter.bindingPrinter();
await SunmiPrinter.initPrinter();
await SunmiPrinter.startTransactionPrint(true);
await SunmiPrinter.printText(
restaurant.title,
style: SunmiStyle(
align: SunmiPrintAlign.CENTER,
),
);
await SunmiPrinter.lineWrap(1);
await SunmiPrinter.printText(
'ใบเสร็จ',
style: SunmiStyle(
align: SunmiPrintAlign.CENTER,
),
);
await SunmiPrinter.line();
await SunmiPrinter.printRow(cols: [
ColumnMaker(text: 'NO:', width: 10, align: SunmiPrintAlign.LEFT),
ColumnMaker(text: order.id, width: 20, align: SunmiPrintAlign.RIGHT),
]);
await SunmiPrinter.printRow(cols: [
ColumnMaker(text: 'Time:', width: 10, align: SunmiPrintAlign.LEFT),
ColumnMaker(
text: DateFormat('dd/MM/yyyy HH:mm')
.format(order.paidTime ?? DateTime.now()),
width: 20,
align: SunmiPrintAlign.RIGHT),
]);
await SunmiPrinter.line();
await SunmiPrinter.bold();
await SunmiPrinter.printRow(cols: [
ColumnMaker(text: 'Menu', width: 15, align: SunmiPrintAlign.LEFT),
ColumnMaker(text: 'Price', width: 15, align: SunmiPrintAlign.RIGHT),
]);
await SunmiPrinter.resetBold();
for (var item in order.cart.items) {
await SunmiPrinter.printRow(cols: [
ColumnMaker(
text: '${item.amount} x ${item.product.title}',
width: 20,
align: SunmiPrintAlign.LEFT),
ColumnMaker(
text: item.totalPrice.toString(),
width: 10,
align: SunmiPrintAlign.RIGHT),
]);
}
await SunmiPrinter.line();
await SunmiPrinter.printRow(cols: [
ColumnMaker(text: 'Total', width: 10, align: SunmiPrintAlign.LEFT),
ColumnMaker(
text: '฿${order.cart.totalPrice}',
width: 20,
align: SunmiPrintAlign.RIGHT),
]);
await SunmiPrinter.lineWrap(1);
await SunmiPrinter.printText(
'ขอบคุณที่มาอุดหนุนค่ะ',
style: SunmiStyle(
align: SunmiPrintAlign.CENTER,
fontSize: SunmiFontSize.SM,
),
);
await SunmiPrinter.printText(
'Powered by Dr.Dish',
style: SunmiStyle(
align: SunmiPrintAlign.CENTER,
fontSize: SunmiFontSize.SM,
),
);
await SunmiPrinter.lineWrap(3);
await SunmiPrinter.exitTransactionPrint(true);
Here result
as you can see, the character is stack on each other on lines that use printRow. (printText working fine)
and it working fine when I change to English.
What do I miss or this is a bug? I tried to change column size and word length, but still not working.
return SfRadialGauge(
title: GaugeTitle(
text: 'Speedometer',
textStyle:
const TextStyle(fontSize: 14.0, fontWeight: FontWeight.bold)),
axes: <RadialAxis>[
RadialAxis(
minimum: 0,
maximum: 320,
startAngle: 180,
endAngle: 0,
// showLabels: false,
maximumLabels: 320,
onLabelCreated: _handleLabelCreated,
canRotateLabels: true,
labelsPosition: ElementsPosition.outside,
ticksPosition: ElementsPosition.outside,
showTicks: false,
radiusFactor: 1.1,
axisLineStyle: AxisLineStyle(
thickness: 5,
dashArray: <double>[(320+100) / 5, 3],
// color: Color(0xFF66BB6A)
gradient: SweepGradient(colors: <Color>[
Color(0xFFE7627D),
Color(0xFF231557),
Color(0xFF44107A),
Color(0xFFFF1361),
Color(0xFFFFF800),
], stops: <double>[
0,
100,
190,
240,
320
])
),
/* ranges: <GaugeRange>[
GaugeRange(
startValue: 0,
endValue: 100,
color: Colors.green,
),
GaugeRange(
startValue: 100,
endValue: 210,
color: Colors.orange,
),
GaugeRange(
startValue: 210,
endValue: 320,
color: Colors.red,
)
],*/
annotations: <GaugeAnnotation>[
GaugeAnnotation(
angle: 180,
horizontalAlignment: GaugeAlignment.near,
positionFactor: 0.78,
verticalAlignment: GaugeAlignment.near,
widget: Text(
"0",
style: TextStyle(
color: Colors.black,
fontWeight: FontWeight.bold,
fontSize: 14,
),
)),
GaugeAnnotation(
angle: 0,
horizontalAlignment: GaugeAlignment.far,
positionFactor: 0.85,
verticalAlignment: GaugeAlignment.near,
widget: Text(
"320",
style: TextStyle(
color: Colors.black,
fontWeight: FontWeight.bold,
fontSize: 14,
),
)),
GaugeAnnotation(
axisValue: 100,
positionFactor: 0.5,
angle: 90,
widget: Column(children: [
Center(
child: RichText(
textAlign: TextAlign.center,
text: TextSpan(
text: '223\n',
style: TextStyle(
color: Colors.black,
fontWeight: FontWeight.bold,
fontSize: 30,
),
children: [
TextSpan(
text: 'Points earned this month',
style: TextStyle(
color: Colors.black,
fontWeight: FontWeight.normal,
fontSize: 12,
),
)
],
)),
)
]))
],
pointers: <GaugePointer>[
MarkerPointer(
value: 223,
markerHeight: 15,
markerWidth: 15,
enableDragging: true,
overlayRadius: 12,
borderColor: Colors.green,
borderWidth: 2,
color: Colors.white,
markerType: MarkerType.circle)
],
)
]);
void _handleLabelCreated(AxisLabelCreatedArgs args) {
if (args.text == '30') {
args.text = '£0 - £4';
} else if (args.text == '100') {
args.text = '£4 - £8';
} else if (args.text == '165') {
args.text = '£8 - £12';
} else if (args.text == '235') {
args.text = '£12 - £16';
} else if (args.text == '290') {
args.text = '£16 - £20';
} else {
args.text = '';
}
I have to develop this type of UI using plugin.but there is some point remaining like color we are not achieve after pointer and how equally segment divided and how responsive for all device that need to check.
I have done below part from my side and remaining thing need to add that i mention .So suggest me how can i achieve .
Your requirement can be achieved with help of the ranges property, MarkerPointer onValueChanging callback in the SfRadialGauge. Added _buildRanges method to find the segment length based on the max value and return the list of the GaugeRange, and added _buildGaugeRange method to create GaugeRange based on the given start, end, and _pointerValue value. The minimum value to the marker range is considered an active range, and the maximum value to the marker range is considered an inactive range in the _buildGaugeRange method. The GaugeRange is colored based on the active and inactive range.
We have prepared and shared a code snippet below for your reference.
class _MyHomePageState extends State<MyHomePage> {
double _pointerValue = 256;
int _segmentsCount = 5;
late List<LabelDetails> _labels;
#override
void initState() {
_labels = [];
_calculateLabelsPosition();
super.initState();
}
#override
Widget build(BuildContext context) {
return Scaffold(
body: Column(
children: [
SfRadialGauge(
title: const GaugeTitle(
text: 'Speedometer',
textStyle:
TextStyle(fontSize: 14.0, fontWeight: FontWeight.bold)),
axes: <RadialAxis>[
RadialAxis(
minimum: 0,
maximum: 320,
startAngle: 180,
endAngle: 0,
maximumLabels: 320,
canScaleToFit: true,
interval: 1,
onLabelCreated: _handleLabelCreated,
canRotateLabels: true,
labelsPosition: ElementsPosition.outside,
showTicks: false,
radiusFactor: 1.1,
pointers: <GaugePointer>[
MarkerPointer(
onValueChanging: (dynamic args) {
setState(() {
_pointerValue = args.value;
});
},
value: _pointerValue,
enableDragging: true,
color: Colors.white,
borderColor: Colors.green,
borderWidth: 3,
markerType: MarkerType.circle,
markerHeight: 15,
markerWidth: 15,
overlayRadius: 0,
)
],
ranges: _buildRanges(),
annotations: <GaugeAnnotation>[
const GaugeAnnotation(
angle: 180,
horizontalAlignment: GaugeAlignment.far,
positionFactor: 0.75,
verticalAlignment: GaugeAlignment.near,
widget: Padding(
padding: EdgeInsets.only(top: 5),
child: Text(
"0",
style: TextStyle(
color: Colors.black,
fontWeight: FontWeight.bold,
fontSize: 14,
),
),
)),
const GaugeAnnotation(
angle: 0,
horizontalAlignment: GaugeAlignment.far,
positionFactor: 0.85,
verticalAlignment: GaugeAlignment.near,
widget: Padding(
padding: EdgeInsets.only(top: 5),
child: Text(
"320",
style: TextStyle(
color: Colors.black,
fontWeight: FontWeight.bold,
fontSize: 14,
),
),
)),
GaugeAnnotation(
widget:
Column(mainAxisSize: MainAxisSize.min, children: [
Center(
child: RichText(
textAlign: TextAlign.center,
text: TextSpan(
text: '${_pointerValue.round()}\n',
style: const TextStyle(
color: Colors.black,
fontWeight: FontWeight.bold,
fontSize: 30,
),
children: const [
TextSpan(
text: 'Points earned this month',
style: TextStyle(
color: Colors.black,
fontWeight: FontWeight.normal,
fontSize: 12,
),
)
],
)),
)
]))
],
),
]),
ElevatedButton(
onPressed: () {
setState(() {
_segmentsCount = 7;
_calculateLabelsPosition();
});
},
child: const Text('Update Segment count'))
],
),
);
}
void _calculateLabelsPosition() {
_labels.clear();
// Length of the each segment.
double segmentLength = 320 / _segmentsCount;
double start = segmentLength / 2;
for (int i = 0; i < _segmentsCount; i++) {
_labels.add(LabelDetails(start.toInt(), '£${i * 4} - £${(i + 1) * 4}'));
start += segmentLength;
}
}
void _handleLabelCreated(AxisLabelCreatedArgs args) {
for (int i = 0; i < _segmentsCount; i++) {
LabelDetails details = _labels[i];
if (details.labelPoint == int.parse(args.text)) {
args.text = details.customizedLabel;
return;
}
}
args.text = '';
}
// Return the list of gauge range
List<GaugeRange> _buildRanges() {
List<GaugeRange> ranges = [];
// Gap value between two range
int gap = 2;
// Length of the each segment without gap.
double segmentLength =
(320 - ((_segmentsCount - 1) * gap)) / _segmentsCount;
double start = 0;
for (int i = 0; i < _segmentsCount; i++) {
_buildGaugeRange(start, start + segmentLength, ranges);
start += segmentLength + gap;
}
return ranges;
}
// Method to create a GaugeRange based on start, end and pointerValue and assigned
// color based on active and inactive range.
void _buildGaugeRange(double start, double end, List<GaugeRange> ranges) {
if (_pointerValue >= start && _pointerValue <= end) {
ranges.add(GaugeRange(
startValue: start, endValue: _pointerValue, color: Colors.green));
ranges.add(GaugeRange(
startValue: _pointerValue,
endValue: end,
color: const Color.fromARGB(255, 82, 86, 97),
));
} else if (_pointerValue >= end) {
ranges.add(GaugeRange(
startValue: start,
endValue: end,
color: Colors.green,
));
} else {
ranges.add(GaugeRange(
startValue: start,
endValue: end,
color: const Color.fromARGB(255, 82, 86, 97),
));
}
}
}
class LabelDetails {
LabelDetails(this.labelPoint, this.customizedLabel);
int labelPoint;
String customizedLabel;
}
Screenshot:
I want to print the events from an event list that I'm getting from API. In this code, the events attribute of the Calendar widget is hardcoded. what should I do?
events Map(It's the Map of events that is getting passed on to the events attribute of calender, instead of this i want to pass my own list of events which im getting from API)
final Map<DateTime, List<CleanCalendarEvent>> events = {
DateTime(DateTime.now().year, DateTime.now().month, DateTime.now().day): [
CleanCalendarEvent('Event A',
startTime: DateTime(DateTime.now().year, DateTime.now().month,
DateTime.now().day + 1, 10, 0),
endTime: DateTime(DateTime.now().year, DateTime.now().month,
DateTime.now().day + 1, 12, 0),
description: 'A special event',
color: Colors.orangeAccent),
],
};
void _handleData(date) {
setState(() {
selectedDay = date;
selectedEvent = events[selectedDay] ?? [];
});
}
Calendar widget inside the body of Scaffold
Calendar(
startOnMonday: false,
selectedColor: Colors.blue,
todayColor: Colors.red,
eventColor: Colors.green,
eventDoneColor: Colors.amber,
bottomBarColor: Colors.deepOrange,
onRangeSelected: (range) {
print('selected Day ${range.from},${range.to}');
},
onDateSelected: (date) {
return _handleData(date);
},
events: events,
isExpanded: true,
dayOfWeekStyle: const TextStyle(
fontSize: 12,
color: Colors.blueGrey,
fontWeight: FontWeight.bold,
),
bottomBarTextStyle: const TextStyle(
color: Colors.white,
),
hideBottomBar: false,
hideArrows: false,
weekDays: const [
'Mon',
'Tue',
'Wed',
'Thu',
'Fri',
'Sat',
'Sun'
],
),
I am displaying Google Line chart using below code
google.charts.load('current', {'packages':['corechart']});
//google.charts.setOnLoadCallback(drawChart);
function drawChart(chart_data) {
var jsonData = chart_data;
var data = new google.visualization.DataTable();
data.addColumn('number', 'Day');
data.addColumn('number', 'SOLD');
data.addColumn('number', 'BOUGHT');
$.each(jsonData, function(i, jsonData){
var Day = parseFloat($.trim(jsonData.Day));
var SOLD = parseFloat($.trim(jsonData.SOLD));
var BOUGHT = parseFloat($.trim(jsonData.BOUGHT));
data.addRows([[Day, SOLD, BOUGHT]]);
});
var options = {
fontName: 'Roboto',
height: 400,
fontSize: 12,
chartArea: {
left: '7%',
width: '93%',
height: 350
},
pointSize: 10,
curveType: 'function',
backgroundColor: 'transparent',
tooltip: {
textStyle: {
fontName: 'Roboto',
fontSize: 13
}
},
vAxis: {
title: '',
titleTextStyle: {
fontSize: 13,
italic: false,
color: '#333'
},
viewWindow: {
min: 0
},
textStyle: {
color: '#333'
},
baselineColor: '#ccc',
gridlines:{
color: '#eee',
count: 10
}
},
hAxis: {
textStyle: {
color: '#333'
}
},
legend: {
position: 'top',
alignment: 'center',
textStyle: {
color: '#333'
}
},
series: {
0: { color: '#f58646' },
1: { color: '#66BB6A' }
}
};
var chart = new google.visualization.LineChart(document.getElementById('google-line'));
chart.draw(data, options);
}
Its working fine like below if there data greater than 0
But if there all data value is 0, its display like below
I do not want display negative data and I will have never negative value in my data. So I have added code like below in options as suggested in some questions here.
viewWindow: {
min: 0
},
However its not working and still I have negative values showing. Can anyone help me here for solve the puzzle? Also in horizontal line its missing dates and show in batch of 5 like 5, 10, 15, its possible to show all?
Thanks!
that looks like some sort of bug with the 'current' version.
if we use version '45' it works properly.
google.charts.load('45', ...
see following working snippet...
google.charts.load('45', {
packages: ['corechart']
}).then(function() {
var data = new google.visualization.DataTable();
data.addColumn('number', 'Day');
data.addColumn('number', 'SOLD');
data.addColumn('number', 'BOUGHT');
data.addRows([
[0, 0, 0],
[5, 0, 0],
[10, 0, 0],
[15, 0, 0],
[20, 0, 0],
[25, 0, 0],
[30, 0, 0]
]);
var options = {
fontName: 'Roboto',
height: 400,
fontSize: 12,
chartArea: {
left: '7%',
width: '93%',
height: 350
},
pointSize: 10,
curveType: 'function',
backgroundColor: 'transparent',
tooltip: {
textStyle: {
fontName: 'Roboto',
fontSize: 13
}
},
vAxis: {
title: '',
titleTextStyle: {
fontSize: 13,
italic: false,
color: '#333'
},
viewWindow: {
min: 0
},
textStyle: {
color: '#333'
},
baselineColor: '#ccc',
gridlines: {
color: '#eee',
count: 10
}
},
hAxis: {
textStyle: {
color: '#333'
}
},
legend: {
position: 'top',
alignment: 'center',
textStyle: {
color: '#333'
}
},
series: {
0: {
color: '#f58646'
},
1: {
color: '#66BB6A'
}
}
};
var chart = new google.visualization.LineChart(document.getElementById('google-line'));
chart.draw(data, options);
});
<script src="https://www.gstatic.com/charts/loader.js"></script>
<div id="google-line"></div>
or, when using the 'current' version,
if we add a max value to the viewWindow, then it will work...
google.charts.load('current', {
packages: ['corechart']
}).then(function() {
var data = new google.visualization.DataTable();
data.addColumn('number', 'Day');
data.addColumn('number', 'SOLD');
data.addColumn('number', 'BOUGHT');
data.addRows([
[0, 0, 0],
[5, 0, 0],
[10, 0, 0],
[15, 0, 0],
[20, 0, 0],
[25, 0, 0],
[30, 0, 0]
]);
var options = {
fontName: 'Roboto',
height: 400,
fontSize: 12,
chartArea: {
left: '7%',
width: '93%',
height: 350
},
pointSize: 10,
curveType: 'function',
backgroundColor: 'transparent',
tooltip: {
textStyle: {
fontName: 'Roboto',
fontSize: 13
}
},
vAxis: {
title: '',
titleTextStyle: {
fontSize: 13,
italic: false,
color: '#333'
},
viewWindow: {
min: 0,
max: 1
},
textStyle: {
color: '#333'
},
baselineColor: '#ccc',
gridlines: {
color: '#eee',
count: 10
}
},
hAxis: {
textStyle: {
color: '#333'
}
},
legend: {
position: 'top',
alignment: 'center',
textStyle: {
color: '#333'
}
},
series: {
0: {
color: '#f58646'
},
1: {
color: '#66BB6A'
}
}
};
var chart = new google.visualization.LineChart(document.getElementById('google-line'));
chart.draw(data, options);
});
<script src="https://www.gstatic.com/charts/loader.js"></script>
<div id="google-line"></div>
I want to mark the event once every 4 days.
example today is the 1st, mark the event will be available on the 5th, 10th, 15th, 20th, 25th, 30th, etc.
if today is the 3rd, the event will be available on the 8th, 13th, 18th, etc.
how does that function work?
I use this calendar plugin
https://pub.dev/packages/flutter_calendar_carousel
Following is the function to mark event manually:
EventList<Event> _markedDateMap = new EventList<Event>();
build(){
_calendarCarouselNoHeader = CalendarCarousel<Event>(
...
markedDatesMap: _markedDateMap,
...
),
}
#override
void initState() {
_markedDateMap.add(
new DateTime(2020, 2, 26),
new Event(
date: new DateTime(2020, 2, 26),
title: 'Event 5',
icon: _eventIcon,
));
_markedDateMap.add(
new DateTime(2020, 2, 26),
new Event(
date: new DateTime(2020, 2, 26),
title: 'Event 5',
icon: _eventIcon,
));
super.initState();
}
Any anwser will appreciated.
You can copy paste run full code below
working demo show when pass start date time with
addMarker(DateTime(2020, 2, 01));
addMarker(DateTime(2020, 2, 03));
code snippet
addMarker(DateTime startEventDateTime) {
var eventDateTime = startEventDateTime;
for(int i=0; i<5; i++) {
if(eventDateTime.day == 1) {
eventDateTime = eventDateTime.add(Duration(days: (4)));
} else {
eventDateTime = eventDateTime.add(Duration(days: (5)));
}
print(eventDateTime.toLocal());
_markedDateMap.add(
eventDateTime,
Event(
date: eventDateTime,
title: 'Event $i',
icon: _eventIcon,
));
}
}
working demo
full code
import 'package:flutter/material.dart';
import 'package:flutter_calendar_carousel/flutter_calendar_carousel.dart'
show CalendarCarousel;
import 'package:flutter_calendar_carousel/classes/event.dart';
import 'package:flutter_calendar_carousel/classes/event_list.dart';
import 'package:intl/intl.dart' show DateFormat;
void main() => runApp( MyApp());
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(
title: 'dooboolab flutter calendar',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: MyHomePage(title: 'Flutter Calendar Carousel Example'),
);
}
}
class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);
final String title;
#override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
DateTime _currentDate = DateTime(2020, 2, 17);
DateTime _currentDate2 = DateTime(2020, 2, 17);
String _currentMonth = DateFormat.yMMM().format(DateTime(2020, 2, 17));
DateTime _targetDateTime = DateTime(2020, 2, 17);
// List<DateTime> _markedDate = [DateTime(2018, 9, 20), DateTime(2018, 10, 11)];
static Widget _eventIcon = Container(
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.all(Radius.circular(1000)),
border: Border.all(color: Colors.blue, width: 2.0)),
child: Icon(
Icons.person,
color: Colors.amber,
),
);
EventList<Event> _markedDateMap = EventList<Event>();
CalendarCarousel _calendarCarousel, _calendarCarouselNoHeader;
#override
void initState() {
addMarker(DateTime(2020, 2, 03));
super.initState();
}
addMarker(DateTime startEventDateTime) {
var eventDateTime = startEventDateTime;
for(int i=0; i<5; i++) {
if(eventDateTime.day == 1) {
eventDateTime = eventDateTime.add(Duration(days: (4)));
} else {
eventDateTime = eventDateTime.add(Duration(days: (5)));
}
print(eventDateTime.toLocal());
_markedDateMap.add(
eventDateTime,
Event(
date: eventDateTime,
title: 'Event $i',
icon: _eventIcon,
));
}
}
#override
Widget build(BuildContext context) {
/// Example with custom icon
_calendarCarousel = CalendarCarousel<Event>(
onDayPressed: (DateTime date, List<Event> events) {
this.setState(() => _currentDate = date);
events.forEach((event) => print(event.title));
},
weekendTextStyle: TextStyle(
color: Colors.red,
),
thisMonthDayBorderColor: Colors.grey,
// weekDays: null, /// for pass null when you do not want to render weekDays
headerText: 'Custom Header',
// markedDates: _markedDate,
weekFormat: true,
markedDatesMap: _markedDateMap,
height: 200.0,
selectedDateTime: _currentDate2,
showIconBehindDayText: true,
// daysHaveCircularBorder: false, /// null for not rendering any border, true for circular border, false for rectangular border
customGridViewPhysics: NeverScrollableScrollPhysics(),
markedDateShowIcon: true,
markedDateIconMaxShown: 2,
selectedDayTextStyle: TextStyle(
color: Colors.yellow,
),
todayTextStyle: TextStyle(
color: Colors.blue,
),
markedDateIconBuilder: (event) {
return event.icon;
},
minSelectedDate: _currentDate.subtract(Duration(days: 360)),
maxSelectedDate: _currentDate.add(Duration(days: 360)),
todayButtonColor: Colors.transparent,
todayBorderColor: Colors.green,
markedDateMoreShowTotal:
false, // null for not showing hidden events indicator
// markedDateIconMargin: 9,
// markedDateIconOffset: 3,
);
/// Example Calendar Carousel without header and custom prev & next button
_calendarCarouselNoHeader = CalendarCarousel<Event>(
todayBorderColor: Colors.green,
onDayPressed: (DateTime date, List<Event> events) {
this.setState(() => _currentDate2 = date);
events.forEach((event) => print(event.title));
},
daysHaveCircularBorder: true,
showOnlyCurrentMonthDate: false,
weekendTextStyle: TextStyle(
color: Colors.red,
),
thisMonthDayBorderColor: Colors.grey,
weekFormat: false,
// firstDayOfWeek: 4,
markedDatesMap: _markedDateMap,
height: 420.0,
selectedDateTime: _currentDate2,
targetDateTime: _targetDateTime,
customGridViewPhysics: NeverScrollableScrollPhysics(),
markedDateCustomShapeBorder: CircleBorder(
side: BorderSide(color: Colors.yellow)
),
markedDateCustomTextStyle: TextStyle(
fontSize: 18,
color: Colors.blue,
),
showHeader: false,
// markedDateIconBuilder: (event) {
// return Container(
// color: Colors.blue,
// );
// },
todayTextStyle: TextStyle(
color: Colors.blue,
),
todayButtonColor: Colors.yellow,
selectedDayTextStyle: TextStyle(
color: Colors.yellow,
),
minSelectedDate: _currentDate.subtract(Duration(days: 360)),
maxSelectedDate: _currentDate.add(Duration(days: 360)),
prevDaysTextStyle: TextStyle(
fontSize: 16,
color: Colors.pinkAccent,
),
inactiveDaysTextStyle: TextStyle(
color: Colors.tealAccent,
fontSize: 16,
),
onCalendarChanged: (DateTime date) {
this.setState(() {
_targetDateTime = date;
_currentMonth = DateFormat.yMMM().format(_targetDateTime);
});
},
onDayLongPressed: (DateTime date) {
print('long pressed date $date');
},
);
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: SingleChildScrollView(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
//custom icon
Container(
margin: EdgeInsets.symmetric(horizontal: 16.0),
child: _calendarCarousel,
), // This trailing comma makes auto-formatting nicer for build methods.
//custom icon without header
Container(
margin: EdgeInsets.only(
top: 30.0,
bottom: 16.0,
left: 16.0,
right: 16.0,
),
child: Row(
children: <Widget>[
Expanded(
child: Text(
_currentMonth,
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 24.0,
),
)),
FlatButton(
child: Text('PREV'),
onPressed: () {
setState(() {
_targetDateTime = DateTime(_targetDateTime.year, _targetDateTime.month -1);
_currentMonth = DateFormat.yMMM().format(_targetDateTime);
});
},
),
FlatButton(
child: Text('NEXT'),
onPressed: () {
setState(() {
_targetDateTime = DateTime(_targetDateTime.year, _targetDateTime.month +1);
_currentMonth = DateFormat.yMMM().format(_targetDateTime);
});
},
)
],
),
),
Container(
margin: EdgeInsets.symmetric(horizontal: 16.0),
child: _calendarCarouselNoHeader,
), //
],
),
));
}
}