How do I disable the secondary line that appears after clicking on a series in the legend of a Google chart? - charts

If you look at this line chart and click on Dogs in the legend, you'll notice a secondary line appears next to the respective series in the graph.
How can I prevent this line from appearing? I'm aware that I can remove all interactivity by doing this:
var options = {
enableInteractivity: false
};
However, this will suppress tool tips as well. I only want to remove the interactivity in the legend.

you can override the chart's selection on the 'select' event,
if the selection row is null, then the legend is selected...
see following working snippet,
the selection is removed when the legend is selected...
google.charts.load('current', {
packages: ['corechart']
}).then(function () {
var data = new google.visualization.DataTable();
data.addColumn('number', 'X');
data.addColumn('number', 'Dogs');
data.addColumn('number', 'Cats');
data.addRows([
[0, 0, 0], [1, 10, 5], [2, 23, 15], [3, 17, 9], [4, 18, 10], [5, 9, 5],
[6, 11, 3], [7, 27, 19], [8, 33, 25], [9, 40, 32], [10, 32, 24], [11, 35, 27],
[12, 30, 22], [13, 40, 32], [14, 42, 34], [15, 47, 39], [16, 44, 36], [17, 48, 40],
[18, 52, 44], [19, 54, 46], [20, 42, 34], [21, 55, 47], [22, 56, 48], [23, 57, 49],
[24, 60, 52], [25, 50, 42], [26, 52, 44], [27, 51, 43], [28, 49, 41], [29, 53, 45],
[30, 55, 47], [31, 60, 52], [32, 61, 53], [33, 59, 51], [34, 62, 54], [35, 65, 57],
[36, 62, 54], [37, 58, 50], [38, 55, 47], [39, 61, 53], [40, 64, 56], [41, 65, 57],
[42, 63, 55], [43, 66, 58], [44, 67, 59], [45, 69, 61], [46, 69, 61], [47, 70, 62],
[48, 72, 64], [49, 68, 60], [50, 66, 58], [51, 65, 57], [52, 67, 59], [53, 70, 62],
[54, 71, 63], [55, 72, 64], [56, 73, 65], [57, 75, 67], [58, 70, 62], [59, 68, 60],
[60, 64, 56], [61, 60, 52], [62, 65, 57], [63, 67, 59], [64, 68, 60], [65, 69, 61],
[66, 70, 62], [67, 72, 64], [68, 75, 67], [69, 80, 72]
]);
var options = {
hAxis: {
title: 'Time'
},
vAxis: {
title: 'Popularity'
},
series: {
1: {curveType: 'function'}
}
};
var chart = new google.visualization.LineChart(document.getElementById('chart_div'));
google.visualization.events.addListener(chart, 'select', function () {
var selection = chart.getSelection();
if (selection.length > 0) {
if (selection[0].row === null) {
chart.setSelection([]);
}
}
});
chart.draw(data, options);
});
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
<div id="chart_div"></div>

Related

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

Google Bar Intervals Chart options

I've created a google line intervals chart. An example google provided can be seen here https://jsfiddle.net/4tgfzdyj/ I'm trying to convert this to a Bar Intervals chart, some explanation and var options are given here: https://developers.google.com/chart/interactive/docs/gallery/intervals
However, I couldn't do it, even with the example Google provided, I can't get the result given in the picture on the link. When I change the var options for Bar intervals chart, a blank page appears. Unfortunately, Google didn't provide a full working code or jsfiddle for this. and I couldn't get it done. I'm missing something probably? A little help is appreciated. Thanks.
var options_bars = {
title: 'Bars, default',
curveType: 'function',
series: [{'color': '#D9544C'}],
intervals: { style: 'bars' },
legend: 'none',
};
following is a working snippet of the line intervals from the fiddle provided...
google.charts.load('current', {'packages':['corechart']});
google.charts.setOnLoadCallback(drawChart);
function drawChart() {
var data = new google.visualization.DataTable();
data.addColumn('number', 'x');
data.addColumn('number', 'values');
data.addColumn({id:'i0', type:'number', role:'interval'});
data.addColumn({id:'i1', type:'number', role:'interval'});
data.addColumn({id:'i2', type:'number', role:'interval'});
data.addColumn({id:'i2', type:'number', role:'interval'});
data.addColumn({id:'i2', type:'number', role:'interval'});
data.addColumn({id:'i2', type:'number', role:'interval'});
data.addRows([
[1, 100, 90, 110, 85, 96, 104, 120],
[2, 120, 95, 130, 90, 113, 124, 140],
[3, 130, 105, 140, 100, 117, 133, 139],
[4, 90, 85, 95, 85, 88, 92, 95],
[5, 70, 74, 63, 67, 69, 70, 72],
[6, 30, 39, 22, 21, 28, 34, 40],
[7, 80, 77, 83, 70, 77, 85, 90],
[8, 100, 90, 110, 85, 95, 102, 110]]);
// The intervals data as narrow lines (useful for showing raw source data)
var options_lines = {
title: 'Line intervals, default',
curveType: 'function',
lineWidth: 4,
intervals: { 'style':'line' },
legend: 'none'
};
var chart_lines = new google.visualization.LineChart(document.getElementById('chart_lines'));
chart_lines.draw(data, options_lines);
}
<script src="https://www.gstatic.com/charts/loader.js"></script>
<div id="chart_lines" style="width: 900px; height: 500px;"></div>
if you want to change to bars, using the following options,
var options_bars = {
title: 'Bars, default',
curveType: 'function',
series: [{'color': '#D9544C'}],
intervals: { style: 'bars' },
legend: 'none',
};
then you also need to change the draw statement,
because the new options have a different variable name...
from...
chart_lines.draw(data, options_lines);
to...
chart_lines.draw(data, options_bars);
see following working snippet...
google.charts.load('current', {'packages':['corechart']});
google.charts.setOnLoadCallback(drawChart);
function drawChart() {
var data = new google.visualization.DataTable();
data.addColumn('number', 'x');
data.addColumn('number', 'values');
data.addColumn({id:'i0', type:'number', role:'interval'});
data.addColumn({id:'i1', type:'number', role:'interval'});
data.addColumn({id:'i2', type:'number', role:'interval'});
data.addColumn({id:'i2', type:'number', role:'interval'});
data.addColumn({id:'i2', type:'number', role:'interval'});
data.addColumn({id:'i2', type:'number', role:'interval'});
data.addRows([
[1, 100, 90, 110, 85, 96, 104, 120],
[2, 120, 95, 130, 90, 113, 124, 140],
[3, 130, 105, 140, 100, 117, 133, 139],
[4, 90, 85, 95, 85, 88, 92, 95],
[5, 70, 74, 63, 67, 69, 70, 72],
[6, 30, 39, 22, 21, 28, 34, 40],
[7, 80, 77, 83, 70, 77, 85, 90],
[8, 100, 90, 110, 85, 95, 102, 110]]);
// The intervals data as narrow lines (useful for showing raw source data)
var options_bars = {
title: 'Bars, default',
curveType: 'function',
series: [{'color': '#D9544C'}],
intervals: { style: 'bars' },
legend: 'none',
};
var chart_lines = new google.visualization.LineChart(document.getElementById('chart_lines'));
chart_lines.draw(data, options_bars);
}
<script src="https://www.gstatic.com/charts/loader.js"></script>
<div id="chart_lines" style="width: 900px; height: 500px;"></div>

How to extract every n continuous elements in a list in scala? [duplicate]

This question already has answers here:
Split list into multiple lists with fixed number of elements
(5 answers)
Closed 5 years ago.
Just to say I have a list with 100 elements. I would like to extract lists with length = 5(i.e., there will be 20 extracted lists, which is element 0-4, 5-9, ... ). Is there any elegant way to do this?
you need to group by how many elemes you want in each chunk
scala> (0 to 99).toList.grouped(5).toList
res5: List[List[Int]] = List(List(0, 1, 2, 3, 4), List(5, 6, 7, 8, 9), List(10, 11, 12, 13, 14), List(15, 16, 17, 18, 19), List(20, 21, 22, 23, 24), List(25, 26, 27, 28, 29), List(30, 31, 32, 33, 34), List(35, 36, 37, 38, 39), List(40, 41, 42, 43, 44), List(45, 46, 47, 48, 49), List(50, 51, 52, 53, 54), List(55, 56, 57, 58, 59), List(60, 61, 62, 63, 64), List(65, 66, 67, 68, 69), List(70, 71, 72, 73, 74), List(75, 76, 77, 78, 79), List(80, 81, 82, 83, 84), List(85, 86, 87, 88, 89), List(90, 91, 92, 93, 94), List(95, 96, 97, 98, 99))
see - Split list into multiple lists with fixed number of elements

Elixir stream audio to users

The following code streams a file to a process.
I want to stream audio/mp3
to many users who will hear it via html5 audio tag.
How can it be done via File.stream!?
defmodule Test do
def start do
p = spawn(Test, :say, [])
send p, {self, "a message"}
end
def say do
receive do
{from, msg} ->
IO.puts "Process #{inspect self} says: #{msg}"
stream_bytes = 128
File.stream!("./song.mp3", [], stream_bytes)
|> Enum.each(fn chunk ->
IO.inspect chunk
end)
say
end
end
end
$: iex test.ex
iex(1)> Test.start
output:
<<171, 46, 254, 26, 163, 32, 178, 27, 0, 75, 17, 35, 4, 236, 51, 57, 5, 144, 154, 198, 166, 47, 62, 4, 61, 85, 67, 135, 16, 34, 82, 49, 57, 176, 131, 96, 116, 152, 232, 24, 32, 140, 220, 67, 73, 128, 165, 178, 230, 202, ...>>
<<100, 220, 156, 191, 38, 0, 161, 117, 80, 16, 102, 91, 22, 5, 8, 66, 26, 7, 193, 155, 193, 66, 198, 28, 157, 244, 65, 131, 204, 240, 5, 172, 143, 44, 173, 85, 144, 2, 157, 144, 145, 97, 200, 236, 16, 49, 149, 150, 133, 67, ...>>
<<150, 54, 37, 254, 192, 218, 218, 26, 69, 231, 88, 124, 33, 129, 169, 66, 117, 52, 214, 134, 130, 103, 85, 130, 48, 6, 144, 221, 153, 132, 8, 181, 26, 27, 83, 140, 54, 117, 149, 7, 60, 144, 237, 248, 132, 12, 210, 51, 103, 116, ...>>
<<57, 2, 143, 220, 198, 182, 22, 177, 231, 126, 187, 147, 33, 9, 1, 5, 164, 2, 36, 105, 47, 255, 255, 255, 255, 255, 245, 54, 51, 225, 104, 98, 1, 184, 148, 206, 50, 135, 230, 28, 50, 47, 144, 134, 53, 16, 64, 130, 192, 198, ...>>
..............
how can I use JavaScript to read this binary data and hear it via audio tag ?
If you're using a plug based web framework it should be reasonably straight forward. This is possible if you're using plug directly or if you're using it from within phoenix (which is based on plug).
Maybe a plug like this would do the trick
defmodule Audio do
#chunk_size 128
def init(opts), do: opts
def song(conn, _opts) do
conn = conn
|> send_chunked(200)
|> put_resp_header("content-type", "audio/mpeg")
File.stream!("/some/song/somewhere.mp3", [], #chunk_size)
|> Enum.into(conn)
end
end
Maybe you want to hook up your plug to a phoenix router like this
defmodule MyApp.Router do
use MyApp.Web, :router
get "/the_song", Audio, :song
end
Then in your page
<audio src="/the_song">
Your browser does not support the <code>audio</code> element.
</audio>

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]