Line Chart won't cover 100% of Horizontal Axis - charts

I have a graph that won't cover the full chart area Horizontally
Here is the sample data that is used to achieve the graph
[
[
"2021-07-08",
53,
0,
53,
0,
38,
0
],
[
"2021-07-09",
11,
26,
27,
98,
20,
47
],
[
"2021-07-10",
80,
42,
14,
35,
20,
13
],
[
"2021-07-11",
16,
12,
17,
25,
47,
79
],
[
"2021-07-12",
41,
12,
10,
12,
64,
40
],
[
"2021-07-13",
32,
84,
30,
72,
19,
18
],
[
"2021-07-14",
12,
50,
44,
85,
25,
11
],
[
"2021-07-15",
43,
60,
26,
74,
88,
30
]
]
My options are
var options = {
legend: { position: 'bottom' },
chartArea:{left:20, right:0, top:0,width:'100%',height:'75%'}
};
See attached image with result
How do I make the Horizontal axis cover the whole chart?

Related

How to group weekly data in it respective months and plot using Apache Echarts

I have the weekly avg from last 5 years, last year, and the year to date.
I would like to show them in a line graph, but showing the respective months in the xaxis...
for example and based on this year:
January has 4 weeks, so xaxis shows jan and there are 4 marks in the chart representing weeks 1,2,3 and 4;
February also has 4 weeks, so xaxis shows feb and there are 3 marks in the chart representing week 5,6,7 and 8;
and so on;
i'm using:
VueJs: 2.6.10
Echarts: 4.9.0
here is my code:
// var motnhNames = [
// 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun',
// 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'
// ]
var monthNames = [
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38,
39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52
]
var options = {
title: {
text: 'My data'
},
tooltip: {
trigger: 'axis'
},
legend: {
data: ['5 Years', 'Last Year', 'YTD']
},
toolbox: {
show: true,
feature: {
dataZoom: {
yAxisIndex: 'none'
},
dataView: {
readOnly: false
},
magicType: {
type: ['line', 'bar']
},
restore: {},
saveAsImage: {}
}
},
xAxis: {
type: 'category',
boundaryGap: false,
data: monthNames
},
yAxis: {
type: 'value',
},
series: [{
name: '5 Years',
type: 'line',
data: [
19, 46, 34, 33, 16, 3, 6, 33, 20,
25, 5, 29, 48, 36, 1, 28, 48, 1,
34, 22, 50, 38, 11, 11, 37, 11, 28,
15, 14, 5, 7, 2, 46, 3, 12, 10,
20, 50, 39, 17, 50, 7, 27, 6, 5,
11, 35, 25, 50, 18, 40, 30, 35
],
lineStyle: {
type: 'dashed',
width: 5
}
},
{
name: 'Last Year',
type: 'line',
data: [
17, 48, 30, 6, 29, 27, 8, 50, 28,
34, 38, 48, 28, 41, 24, 27, 15, 17,
13, 50, 9, 15, 18, 41, 43, 49, 19,
1, 22, 20, 27, 1, 18, 26, 48, 17,
25, 38, 1, 29, 28, 1, 42, 21, 7,
8, 6, 6, 47, 50, 6, 46, 41
],
lineStyle: {
type: 'dotted',
width: 5
}
},
{
name: 'YTD',
type: 'line',
data: [
17, 48, 30, 6, 29, 27, 8, 50, 28,
34, 38, 48, 28, 41, 24, 27, 15, 17,
13, 50, 9, 15, 18, 41, 43, 49, 19,
1, 22, 20, 27, 1, 18, 26, 48, 17,
25, 38, 1, 29, 28, 1, 42, 21, 7,
8, 6, 6, 47, 50, 6, 46
],
lineStyle: {
type: 'solid',
width: 5
}
}
]
};
thanks in advance
[UPDATE 1]
I added a function that translate the week number to the respective month:
getDateOfWeek(week: number, year: number): string {
let date = (1 + (week - 1) * 7);
let dateOfYear = new Date(year, 0, date)
let month = dateOfYear.toLocaleString('pt-BR', { month: 'short' });
month = month.charAt(0).toUpperCase() + month.slice(1).replace('.', '')
return month;
}
also added a axisLabel:
options: {
...,
axisLabel: {
formatter: (param: number) => {
return this.getDateOfWeek(param, 2021)
},
},
...,
}
Now i have the month name on xaxis as expected... Only need to suppress duplicated names or maybe define a limit for 12 ticks.
I've tried to use xaxis.splitNumber property, but as the docs says, it is not allowed for category axis...
I was wondering, if i could change the week number to a date object, like:
firstWeek = '2021-01-01'
secondWeek = '2021-01-08'
should i change it to time series and work with real dates on X Axis?
not sure if it would solve the problem or bring another :|
here is the result so far:
Solved adding a new xaxis layer and hide the first one...
xAxis: [
{
type: "category",
boundaryGap: false,
data: this.generateData(false, 51),
axisLabel: {
formatter: (param) => {
return this.getMonthFromWeek(param, 2021);
}
},
show: false
},
{
position: "bottom",
type: "category",
data: [
"Jan",
"Fev",
"Mar",
"Abr",
"Mai",
"Jun",
"Jul",
"Ago",
"Set",
"Out",
"Nov",
"Dez"
],
xAxisIndex: 2
}
],
here is sandbox code result!

Flutter : Save and Fetch ImageNetwork from API using SQFlite

I have problem with Insert and Fetch Image From API to local Directory.
So i have code to save image like this :
Save Image Code
Future saveImage(String imgUrl, String imgUrl2) async {
var response = await http.get("$baseURLimage/berita/$imgUrl");
var documentDirectory = await getApplicationDocumentsDirectory();
File file = File(join(documentDirectory.path, imgUrl2));
file.writeAsBytesSync(response.bodyBytes);
print(response);
print(response.bodyBytes);
print(documentDirectory);
print(file);
return file;
}
Button Code
void _saveImage() async {
var saveImage =
await api.saveImage(widget.gambarBerita, widget.gambarBerita);
print(saveImage);
}
In Console give me this :
I/flutter (23336): Instance of 'Response'
I/flutter (23336): [255, 216, 255, 224, 0, 16, 74, 70, 73, 70, 0, 1, 1, 0, 0, 1, 0, 1, 0, 0, 255, 219, 0, 132, 0, 13, 13, 13, 13, 14, 13, 14, 16, 16, 14, 20, 22, 19, 22, 20, 30, 27, 25, 25, 27, 30, 45, 32, 34, 32, 34, 32, 45, 68, 42, 50, 42, 42, 50, 42, 68, 60, 73, 59, 55, 59, 73, 60, 108, 85, 75, 75, 85, 108, 125, 105, 99, 105, 125, 151, 135, 135, 151, 190, 181, 190, 249, 249, 255, 1, 13, 13, 13, 13, 14, 13, 14, 16, 16, 14, 20, 22, 19, 22, 20, 30, 27, 25, 25, 27, 30, 45, 32, 34, 32, 34, 32, 45, 68, 42, 50, 42, 42, 50, 42, 68, 60, 73, 59, 55, 59, 73, 60, 108, 85, 75, 75, 85, 108, 125, 105, 99, 105, 125, 151, 135, 135, 151, 190, 181, 190, 249, 249, 255, 255, 192, 0, 17, 8, 11, 244, 8, 88, 3, 1, 34, 0, 2, 17, 1, 3, 17, 1, 255, 196, 0, 156, 0, 0, 2, 3, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 4, 5, 3, 6, 7, 16, 0, 2, 2, 1, 4, 1, 3, 3, 2, 4, 5, 5, 0, 0, 1, 13, 0, 1, 2, 3, 17, 4, 18, 33, 49, 5, 19, 65, 81, 34, 50, 97, 20, 113, 6, 35, 66, 82, 21, 51, 129, 145, 161, 36, 52, 98, 114, 177, 67, 83, 37, 53, 115, 22, 68, 99, 193, 8
I/flutter (23336): Directory: '/data/user/0/com.example.flutter_news/app_flutter'
I/flutter (23336): File: '/data/user/0/com.example.flutter_news/app_flutter/92dae9b51087d930a32aff53eaded163.jpg'
I/flutter (23336): File: '/data/user/0/com.example.flutter_news/app_flutter/92dae9b51087d930a32aff53eaded163.jpg'
But my images still not saved in my device.
can you help me ?
You can use package https://pub.dev/packages/network_to_file_image
In demo, it download image and show it, so you can see success or not directly
From official introduction
This is a mixture of FileImage and NetworkImage. It will download the image from the url once, save it locally in the file system, and then use it from there in the future.
full example code
import 'dart:async';
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:network_to_file_image/network_to_file_image.dart';
import 'package:path/path.dart' as p;
import 'package:path_provider/path_provider.dart';
String flutterLogoUrl =
"https://upload.wikimedia.org/wikipedia/commons/1/17/Google-flutter-logo.png";
String flutterLogoFileName = "flutter.png";
void main() async {
runApp(
MaterialApp(
home: Demo(
url: flutterLogoUrl,
file: await file(flutterLogoFileName),
),
),
);
}
Future<File> file(String filename) async {
Directory dir = await getApplicationDocumentsDirectory();
String pathName = p.join(dir.path, filename);
return File(pathName);
}
class Demo extends StatelessWidget {
final String url;
final File file;
const Demo({Key key, this.url, this.file}) : super(key: key);
#override
Widget build(BuildContext context) => Scaffold(
appBar: AppBar(title: const Text('Network to file image example')),
body: Padding(
padding: const EdgeInsets.all(30.0),
child: Image(image: NetworkToFileImage(url: url, file: file, debug: true)),
),
);
}
In demo picture, you can see it print image url and saved file path

Errors with UIPickerView

I am getting these errors and i dont even know why
1: Type view controller does not conform with UIViewPickerDataSource
2: method pickerview(pickerView:numberOfRowsInComponent:) has different argument names from those required
Here is my code!
Any help will be appreciated. Thanks
import UIKit
class ViewController: UIViewController,UIPickerViewDataSource,UIPickerViewDelegate {
#IBOutlet weak var timePicker: UIPickerView!
var timePickerData:[[Int]] = [[Int]]()
override func viewDidLoad()
{
super.viewDidLoad()
self.timePicker.delegate = self
self.timePicker.dataSource = self
timePickerData = [[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51,52, 53, 54, 55, 56, 57, 58, 59], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51,52, 53, 54, 55, 56, 57, 58, 59]]
}
override func didReceiveMemoryWarning()
{
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func numberOfComponentsInPickerView(pickerView: UIPickerView) -> Int
{
return timePickerData.count
}
// The number of rows of data
func pickerView(pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int
{
return timePickerData[component].count
}
// The data to return for the row and component (column) that's being passed in
func pickerView(pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> Int?
{
return timePickerData[component][row]
}
}
It seems like you are using XCode 8, but your code uses old Swift 2.2 UIPickerView API. My suggestion for correction:
class ViewController: UIViewController,UIPickerViewDataSource,UIPickerViewDelegate {
#IBOutlet weak var timePicker: UIPickerView!
var timePickerData:[[Int]] = [[Int]]()
override func viewDidLoad()
{
super.viewDidLoad()
self.timePicker.delegate = self
self.timePicker.dataSource = self
timePickerData = [[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51,52, 53, 54, 55, 56, 57, 58, 59], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51,52, 53, 54, 55, 56, 57, 58, 59]]
}
func numberOfComponents(in pickerView: UIPickerView) -> Int {
return timePickerData.count
}
// The number of rows of data
func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int
{
return timePickerData[component].count
}
// The data to return for the row and component (column) that's being passed in
private func pickerView(pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> Int?
{
return timePickerData[component][row]
}
}

Scala's Mutable Queue isn't mutable when in a Map

I'm using scala version 2.10.4 and it appears that a collection.mutable.Queue inside a Map isn't mutable. However a tuple of key to collection.mutable.Queue does appear to be mutable.
scala> scala.util.Properties.scalaPropOrEmpty("version.number")
res0: String = 2.10.4
scala> import scala.collection.mutable.{ Queue => MutableQueue }
import scala.collection.mutable.{Queue=>MutableQueue}
scala> (1 to 50).groupBy(_ % 5).mapValues(nums => MutableQueue(nums:_*))
res1: scala.collection.immutable.Map[Int,scala.collection.mutable.Queue[Int]] = Map(0 -> Queue(5, 10, 15, 20, 25, 30, 35, 40, 45, 50), 1 -> Queue(1, 6, 11, 16, 21, 26, 31, 36, 41, 46), 2 -> Queue(2, 7, 12, 17, 22, 27, 32, 37, 42, 47), 3 -> Queue(3, 8, 13, 18, 23, 28, 33, 38, 43, 48), 4 -> Queue(4, 9, 14, 19, 24, 29, 34, 39, 44, 49))
scala> res1(0).dequeue
res2: Int = 5
scala> res1(0)
res3: scala.collection.mutable.Queue[Int] = Queue(5, 10, 15, 20, 25, 30, 35, 40, 45, 50)
scala> (1 to 50).groupBy(_ % 5).mapValues(nums => MutableQueue(nums:_*)).toSeq
res4: Seq[(Int, scala.collection.mutable.Queue[Int])] = ArrayBuffer((0,Queue(5, 10, 15, 20, 25, 30, 35, 40, 45, 50)), (1,Queue(1, 6, 11, 16, 21, 26, 31, 36, 41, 46)), (2,Queue(2, 7, 12, 17, 22, 27, 32, 37, 42, 47)), (3,Queue(3, 8, 13, 18, 23, 28, 33, 38, 43, 48)), (4,Queue(4, 9, 14, 19, 24, 29, 34, 39, 44, 49)))
scala> res4.find(_._1 == 0).get._2.dequeue
res5: Int = 5
scala> res4.find(_._1 == 0).get._2
res6: scala.collection.mutable.Queue[Int] = Queue(10, 15, 20, 25, 30, 35, 40, 45, 50)
I would expect that res1(0) should reflect the dequeue.
This is because mapValues returns a view, so a new mutable Queue is being created every time you access res1.
You can fix this by using a strict map.
scala> (1 to 50).groupBy(_ % 5).map { case (_, nums) => MutableQueue(nums:_*) }.toList
res20: List[scala.collection.mutable.Queue[Int]] = List(Queue(5, 10, 15, 20, 25, 30, 35, 40, 45, 50), Queue(1, 6, 11, 16, 21, 26, 31, 36, 41, 46), Queue(2, 7, 12, 17, 22, 27, 32, 37, 42, 47), Queue(3, 8, 13, 18, 23, 28, 33, 38, 43, 48), Queue(4, 9, 14, 19, 24, 29, 34, 39, 44, 49))
scala> res20(0).dequeue
res21: Int = 5
scala> res20(0)
res22: scala.collection.mutable.Queue[Int] = Queue(10, 15, 20, 25, 30, 35, 40, 45, 50)

IPython interactive shell output formatting configuration

If there's a quick fix for this, apologies in advance. In the IPython shell, if I have this:
In [1]: x = [i for i in range(100)]
then I get a list printed with each element on a new line if I call it:
In [2]: x
Out[2]: [0
1,
2,
and so on down to 100. Irritating as hell because often I'm calling objects and don't know how long they'll be (and don't want to check beforehand, and don't want my last commands to get pushed up and out of the way). How can I get it to print that result the way it would in regular python? I.e.:
>>> x
[1,2,3,4,5,6,7,8,....
9,10,11, ..... 100]
What you want is to disable pretty print.
$ ipython --help
[...]
--no-pprint
Disable auto auto pretty printing of results.
[...]
Which gives :
$ ipython --no-pprint
[...]
In [1]: x = [i for i in range(100)]
In [2]: x
Out[2]: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99]