I wondered if it was possible to make the circle, that appears once hovered across the Google line chart, have a coloured border?
you can use a style column role to change the style of a point.
point {stroke-width: 2; stroke-color: red;}
see following working snippet,
hover a point to see the style...
google.charts.load('current', {
packages: ['corechart']
}).then(function () {
var data = new google.visualization.DataTable();
data.addColumn('number', 'x');
data.addColumn('number', 'y');
data.addColumn({role: 'style', type: 'string'});
data.addRows([
[0, 1, 'point {stroke-width: 2; stroke-color: red;}'],
[1, 2, 'point {stroke-width: 2; stroke-color: red;}'],
[2, 3, 'point {stroke-width: 2; stroke-color: red;}'],
[3, 4, 'point {stroke-width: 2; stroke-color: red;}'],
[4, 5, 'point {stroke-width: 2; stroke-color: red;}'],
]);
var options = {
legend: 'none'
};
var chart = new google.visualization.LineChart(document.getElementById('chart_div'));
chart.draw(data, options);
});
<script src="https://www.gstatic.com/charts/loader.js"></script>
<div id="chart_div"></div>
Related
My x-axis for google visualisation chart is javascript new Date(year+i, 0, 0). However when I print the line chart. It shows M J S at the bottom with the year number.
How can I remove these M J S (which I presume are May June and September).
the following snippet re-produces the problem, with year number combined with month abbreviations...
2020 M J S 2021 M J S etc...
google.charts.load('current', {
packages: ['corechart']
}).then(function () {
var data = new google.visualization.DataTable();
data.addColumn('date', 'Date');
data.addColumn('number', 'Mutual Fund');
for (var y = 2020; y < 2024; y++) {
for (var m = 0; m < 12; m++) {
data.addRow([new Date(y, m, 1), (10000 + y + m)]);
}
}
var container = document.getElementById('chart');
var chart = new google.visualization.LineChart(container);
chart.draw(data);
});
<script src="https://www.gstatic.com/charts/loader.js"></script>
<div id="chart"></div>
to only show year, you can use hAxis option format.
hAxis: {
format: 'yyyy'
}
however, this could cause the year to repeat (depending on the width of the chart)...
2020 2020 2020 2020 2021 2021 2021
see following snippet...
google.charts.load('current', {
packages: ['corechart']
}).then(function () {
var data = new google.visualization.DataTable();
data.addColumn('date', 'Date');
data.addColumn('number', 'Mutual Fund');
for (var y = 2020; y < 2024; y++) {
for (var m = 0; m < 12; m++) {
data.addRow([new Date(y, m, 1), (10000 + y + m)]);
}
}
var container = document.getElementById('chart');
var chart = new google.visualization.LineChart(container);
chart.draw(data, {
hAxis: {
format: 'yyyy'
}
});
});
<script src="https://www.gstatic.com/charts/loader.js"></script>
<div id="chart"></div>
to ensure the year doesn't repeat, we must also provide hAxis option ticks.
ticks must be in the same format as the data on the x-axis, in this case a date.
so we provide the jan date for each year...
hAxis: {
format: 'yyyy',
ticks: [new Date(2020, 0, 1), new Date(2021, 0, 1), new Date(2022, 0, 1)]
}
you should be able to create the ticks dynamically, from the data.
see following snippet for an example...
google.charts.load('current', {
packages: ['corechart']
}).then(function () {
var data = new google.visualization.DataTable();
data.addColumn('date', 'Date');
data.addColumn('number', 'Mutual Fund');
var ticks = [];
for (var y = 2020; y < 2024; y++) {
for (var m = 0; m < 12; m++) {
data.addRow([new Date(y, m, 1), (10000 + y + m)]);
if (m === 0) {
ticks.push(new Date(y, m, 1));
}
}
}
var container = document.getElementById('chart');
var chart = new google.visualization.LineChart(container);
chart.draw(data, {
hAxis: {
format: 'yyyy',
ticks: ticks
}
});
});
<script src="https://www.gstatic.com/charts/loader.js"></script>
<div id="chart"></div>
Im using line chart from Google Charts. I show date on hAxis (horizontal). My major gridlines show date normally. But there are time labels between date labels. And i dont want time labels.
I tried to put that property in hAxis on chart options but nothing changed
minorGridlines:{textPosition: 'none' }
hAxis options;
hAxis: {titleTextStyle: {color: '#0000ff'},
slantedText:true, slantedTextAngle:60,format: 'd/M/yy',minorGridlines:{textPosition: 'none' },gridlines: {
count: -1,
units: {
days: {format: ['d.MM']},
hours: {format: ['HH:mm']},
}
}
},
is there anyone who knows the solution?
first, remove the options for gridlines.
however, this could cause the same date labels to repeat.
to prevent from repeating,
you can provide your own ticks.
the hAxis.ticks option takes an array, in this case, of dates.
to build the ticks array, we can use data table method --> getColumnRange(colIndex)
this will return the min & max values of the column.
then we can to build our ticks array.
// build hAxis ticks
var hAxisTicks = [];
var dateRange = data.getColumnRange(0);
var oneDay = (24 * 60 * 60 * 1000);
for (var i = dateRange.min.getTime(); i <= dateRange.max.getTime(); i = i + oneDay) {
hAxisTicks.push(new Date(i));
}
see following working snippet...
google.charts.load('current', {
packages: ['corechart']
}).then(function () {
var data = new google.visualization.DataTable();
data.addColumn('date', 'Date');
data.addColumn('number', 'Y');
data.addRows([
[new Date(2019, 0, 1, 0), 10],
[new Date(2019, 0, 1, 6), 20],
[new Date(2019, 0, 1, 12), 30],
[new Date(2019, 0, 1, 18), 40],
[new Date(2019, 0, 2, 0), 10],
[new Date(2019, 0, 2, 6), 20],
[new Date(2019, 0, 2, 12), 30],
[new Date(2019, 0, 2, 18), 40],
[new Date(2019, 0, 3, 0), 10],
[new Date(2019, 0, 3, 6), 20],
[new Date(2019, 0, 3, 12), 30],
[new Date(2019, 0, 3, 18), 40],
[new Date(2019, 0, 4, 0), 10],
[new Date(2019, 0, 4, 6), 20],
[new Date(2019, 0, 4, 12), 30],
[new Date(2019, 0, 4, 18), 40],
]);
// build hAxis ticks
var hAxisTicks = [];
var dateRange = data.getColumnRange(0);
var oneDay = (24 * 60 * 60 * 1000);
for (var i = dateRange.min.getTime(); i <= dateRange.max.getTime(); i = i + oneDay) {
hAxisTicks.push(new Date(i));
}
var chart = new google.visualization.LineChart(document.getElementById('chart_div'));
chart.draw(data, {
hAxis: {
format: 'd/M/yy',
ticks: hAxisTicks
}
});
});
<script src="https://www.gstatic.com/charts/loader.js"></script>
<div id="chart_div"></div>
EDIT
building the ticks manually will cause a performance hit,
but only by a couple milliseconds, which is nothing.
see following working snippet,
540 rows are drawn, the milliseconds it takes to build the ticks are shown in the console...
google.charts.load('current', {
packages: ['corechart']
}).then(function () {
var data = new google.visualization.DataTable();
data.addColumn('date', 'Date');
data.addColumn('number', 'Y');
for (var i = (new Date(2019, 0, 1)).getTime(); i <= (new Date(2019, 3, 1)).getTime(); i = i + (4 * 60 * 60 * 1000)) {
data.addRow([new Date(i), i]);
}
// build hAxis ticks
var test = new Date();
console.log('rows', data.getNumberOfRows());
var hAxisTicks = [];
var dateRange = data.getColumnRange(0);
var oneDay = (24 * 60 * 60 * 1000);
for (var i = dateRange.min.getTime(); i <= dateRange.max.getTime(); i = i + oneDay) {
hAxisTicks.push(new Date(i));
}
console.log('milliseconds', ((new Date()).getTime() - test.getTime()));
var chart = new google.visualization.LineChart(document.getElementById('chart_div'));
chart.draw(data, {
hAxis: {
format: 'd/M/yy',
ticks: hAxisTicks
}
});
});
<script src="https://www.gstatic.com/charts/loader.js"></script>
<div id="chart_div"></div>
My data looks like this:
A B
3 5000
2 6218
4 9435
I need to create a chart where A is the number of points/block size and B is the Value of each point.
For example, the date above will create a line graph where the 2 first points will have the value of 5000, the next 2 points will have the value of 6218, and the next 4 points will have the value of 9435.
The graph I need will look like the automatic one that will be generated for this data:
5000
5000
5000
6218
6218
9435
9435
9435
9435
use the original data table to build a new data table.
for each row in the original table, add a row to the new table however many times 'A' represents.
var x = 0;
for (var row = 0; row < rawData.getNumberOfRows(); row++) {
for (var a = 0; a < rawData.getValue(row, 0); a++) {
chartData.addRow([x, rawData.getValue(row, 1)]);
x++;
}
}
see following working snippet...
google.charts.load('current', {
packages:['corechart']
}).then(function () {
var rawData = google.visualization.arrayToDataTable([
['A', 'B'],
[3, 5000],
[2, 6218],
[4, 9435]
]);
var chartData = new google.visualization.DataTable();
chartData.addColumn('number', 'X');
chartData.addColumn('number', 'Y');
var x = 0;
for (var row = 0; row < rawData.getNumberOfRows(); row++) {
for (var a = 0; a < rawData.getValue(row, 0); a++) {
chartData.addRow([x, rawData.getValue(row, 1)]);
x++;
}
}
var container = document.getElementById('chart_div');
var chart = new google.visualization.LineChart(container);
chart.draw(chartData, {
height: 288,
pointSize: 4,
vAxis: {
minValue: 0
}
});
});
<script src="https://www.gstatic.com/charts/loader.js"></script>
<div id="chart_div"></div>
I followed a tut to help me build a tic tac toe game to keep learning Swift. In doing so I also wanted to add winning slashes for whatever combination that wins.
In my code I have
let winningCombinations = [0, 1, 2], [3, 4, 5], [6, 7, 8], [0, 3, 6], [1, 4, 7], [2, 5, 8], [0, 4, 8], [2, 4, 6]]
these are the buttons tags.
I have created labels that are just color bars with no text to be the slashes.
I connected them one as
#IBOutlet weak var lineFirstRow: UILabel!
then hid the label on the storyboard.
I have been trying things like
let lineRowOne = [0, 1, 2]
if lineRowOne = true {
lineFirstRow.isHidden = true
} else {
lineFirstRow.isHidden = false
}
I know this is not correct.
Not entirely sure what you're trying to achieve, but I suspect your solution will be on something like this:
let winningCombinations = [[0, 1, 2], [3, 4, 5], [6, 7, 8], [0, 3, 6], [1, 4, 7], [2, 5, 8], [0, 4, 8], [2, 4, 6]]
let lineOne = [0, 1, 2]
if winningCombinations.contains(where: { $0 == lineOne })
{
// Do Stuff
}
How to add an marker to leaflet map image overlay by using the image pixel coordinates.
I need to place an marker into map by the image's actual pixel xy coordinates by mentioning the x,y pixel points
Check this Fiddle link for more info.
var osmUrl = 'path/to/custom/image',
h = 709,
w = 709;
var map = L.map('mapid', {
minZoom: 1,
maxZoom: 1,
center: [0, 0],
zoom: 1,
crs: L.CRS.Simple
});
var southWest = map.unproject([0, h], map.getMaxZoom());
var northEast = map.unproject([w, 0], map.getMaxZoom());
var bounds = new L.LatLngBounds(southWest, northEast);
L.imageOverlay(osmUrl, bounds).addTo(map);
map.setMaxBounds(bounds);
// var markerData = [[0,0],[185,362],[277,593],[307,354],[472,472],[473,568],[550,516],[535,370],[230,119]];
var marker = L.marker(map.layerPointToLatLng(map.containerPointToLayerPoint([185, 362])));
marker.addTo(map);
<div id="mapid" style="width:500px;height:400px;></div>
The answer is yes. Your map center was wrong. The axis origin is at the top-left corner.
var map = L.map('mapid', {
minZoom: -3,
maxZoom: 1,
center: [0, -709],
zoom: 1,
crs: L.CRS.Simple
});
Check that fiddle and that other one.