Google Charts (GeoChart) - Zoom in closer - google-visualization

Using Google Charts GeoChart: https://google-developers.appspot.com/chart/interactive/docs/gallery/geochart
Is it possible to zoom in closer than just an overall region? That is, to get to street-view level of a map, and still place markers as seen in the marker example on the link above?
Thanks all for the help...

The API does not support zooming, dragging, or scrolling.

As a trick, I used css zoom property with overflow:hidden on container. But it should be executed after chart.draw(), on google chart ready event.
And if you need to redraw (I'm redrawing on window resize to guarantee responsiveness), you should force zoom to 1 or 100% again before draw it again.
HTML:
<div id="container" style="overflow:hidden; width:..px;">
<div id="chart_div"></div>
</div>
JS (jquery):
$("#chart_div").css("zoom",1);
// [... google chart code generation ...]
google.visualization.events.addListener(chart, 'ready', function() { $("#chart_div").css("zoom",1.4); });
chart_draw(data, options);
It worked for me and it is worth the try.

I had the same problem, and GeoChart proved to be too limited in that regard.
One option is to use Google Maps and Data Layers. If you need markers with colors and sizes, for example, you could do something like the example on the following page (see 'advanced style'):
https://developers.google.com/maps/documentation/javascript/examples/layer-data-quakes
You'll need to implement your own interpolation to determine sizes and colors, but the resulting map/chart will be better than GeoChart alone.

It looks like Google Charts now has an expiremental option called 'explorer' that works for some chart types. See:
https://developers.google.com/chart/interactive/docs/gallery/linechart#Configuration_Options

You could try to generate a select event on marker click and in the event function you could change the region of the chart by changing chartOptions as follows:
google.visualization.events.addListener(chart, 'select', () => {
// console.log(this.continents);
if (continents.includes( continentData.getValue(chart.getSelection()[0].row, 2))) {
chartOptions.region = '053';
// 002 - Africa
// 150 - Europe
// 019 - Americas 021 - Northern America 005- South America 013- Central America 029 - Caribbean
// 142 - Asia
// 009 - Oceania
// 053 - Australia and New Zealand
chart.draw(continentData, chartOptions);
}
});

Related

Charts on Admin-on-rest

I need to do a webpage to finish my uni, and im about 90% done with it, however, im struggling with getting custom Iterators and Charts to work.
Im trying to use Recharts, but i have no idea on how to make it gather the info i want (I need it to get the number of users registered and the number of vaccines they took), but all i see on the documentation is ready results, im not sure if ChartJS will make it any better, and even if it does, im confused on how custom iterators work since i took my "Analytics" one from another StackOverflow question, however that's the least of my worries, since this seems to be simplier than getting the ACTUAL charts to work.
Help would be appreciated since i have 2 weeks to deliver it and im stuck on that, and its CRUCIAL i get that to work.
Oh yes, im also very bad at Javascript so every info is welcome.
EDIT:Forgot to say i've looked around but lots of them are for simplier and static stuff instead of database counts or stuff like that.
Welcome to SO.
1) Recharts wants an array that it needs to iterate over and display. So what I usually do is make the Chart Component a child of a List component.
2) I use the Filter on the List page to select different chart components when the user selects different options from the dropdown (in case your analytics page needs to show different charts from the same page)
^^this is a bit tricky for peeps new to JS but is quite straightforward if you want to get into it.
3) For you i think the best bet will be that you make different List components and resources for each page and just display different charts on their own page.
export const AnalyticsList = (props) => {
return (
<List title="Analytics" {...props} perPage={20} sort={{ field: 'id', order: 'ASC' }}>
<Analytics />
</List>
)
}
here is how the Analytics Component is
import React from 'react';
import {BarChart, Bar, XAxis, YAxis, CartesianGrid, Tooltip, Legend} from 'recharts';
export const Analytics = (props) => {
return (
<BarChart width={800} height={400} data={Object.values(props.data)} margin={{top: 5, right: 30, left: 20, bottom: 5}}>
<XAxis dataKey="name"/>
<YAxis dataKey="charLimit" />
<CartesianGrid strokeDasharray="3 3"/>
<Tooltip/>
<Legend />
<Bar dataKey="charLimit" fill="#82ca9d" />
</BarChart>
);
}
Hope this helps.

resetZoom in Chartjs

I need a help. I followed this tutorial https://www.dyclassroom.com/chartjs/chartjs-how-to-draw-line-graph-using-data-from-mysql-table-and-php.
I managed to start chartjs-plugin-zoom.
Now i want to add button "Reset zoom"
I fallowed this tutorial:
Add zoom event handler to charts for chartjs with chartjs-plugin-zoom
But when i add right after $.ajax({}); in app.js
$('#reset_zoom').click(function() {
mycanvas.resetZoom();
})
and press the button error is displayed:
app.js:131 Uncaught TypeError: mycanvas.resetZoom is not a function
at HTMLButtonElement.<anonymous> (app.js:131)
at HTMLButtonElement.dispatch (datatables.min.js:15)
at HTMLButtonElement.r.handle (datatables.min.js:15)
Can you give me an advice?
Kind of surprised this hasn't been answered yet. I remember running into this myself a while back. You are doing the same thing I was doing..
Effectively what you're doing is trying to run the .resetZoom() function on an HTML canvas element. You need to do this on the chart object, not the canvas element.
YouTube video walking you through it: https://www.youtube.com/watch?v=tWlENvyr9cY
Working CodePen: https://codepen.io/vpolston/pen/MWGVmrX
A couple examples of what not to do..
document.getElementById('myChart').resetZoom() // vanilla JavaScript
or even
$("#myChart").resetZoom() // jQuery
What you actually need to do is tack the .resetZoom() onto the Chart object from when you instantiated the chart. So in your code here:
const myChart = new Chart('myChart', {}
Whatever you set the variable to when you created the chart is what needs to have the .resetZoom(). So this would work:
myChart.resetZoom();
Now to make that a clickable button we can create a function. That function accepts whatever the chart Object was named.
JS
resetZoomBtn = (chart) => {
chart.resetZoom()
};
and then in our HTML we call that function and pass whatever you called the chart when you instantiated it as the parameter.
<div class="chart-container">
<canvas id="myChart"></canvas>
<button onclick="resetZoomBtn(myChart)">reset zoom</button>
</div>
Hopefully that helps anyone who views this question since it comes up at the top of the search results on Google. I know chances of it being marked 'answer' four years later are slim.
Thanks,
VP

On changing the orientation of ion-range.The knob is not working smoothly in ionic 2

I am looking for the range bar which is rotated 90 deg(vertically). When it is rotated vertically I am unable to select to the respective step points in the range bar. Whenever the knob is tried to move is it not moving to the desired step points. The touch functionality is not smooth.
The following is the css:
I am rotating the component using the following CSS. After applying this css property transform: rotate(-90deg) the ion-range step is not properly working in the UI(i.e.,The range slider is not moving properly).If any alternate solution apart from this css property I am open for your suggessions.
ion-range { [The following has the final Rangebar I am looking for ][1]
transform: rotate(-90deg);
position: relative;
}
The following is the html
<ion-range min="1" max="5" step="1" snaps="true" color="primary"
[(ngModel)]="abc"></ion-range>
![1]: https://i.stack.imgur.com/aODnC.png

ion-slides looping trick - not updating

I am trying to pull off a "trick" in ionic2 as follows:
- I have one slide set to loop.
- When the slide is swiped I increase or decrease a variable
- that variable will cause different data to display in the slide.
This way I can get the full UI experience of the slides component without hardcoding or pre-loading all the other slides.
For eg lets say you are viewing data by day, I want to be able to slide back and forth to look at data from previous days. Given the change I will just reload the relevant days data.
It ALMOST works except that the slider doesnt seem to refresh properly when looping.
Take a look this
http://plnkr.co/edit/VlxrNO7I6sqLGHsLdB9R?p=preview
<ion-slides loop="true" (ionSlidePrevEnd)="slideChanged(-1)" (ionSlideNextEnd)="slideChanged(1)">
<ion-slide>Slide{{newval}}
Test
</ion-slide>
</ion-slides>
</ion-content>
Controller
export class HomePage {
appName = 'Ionic App';
newval: number = 0;
constructor(public navController: NavController) { }
slideChanged(step: number) {
this.newval = this.newval + step;
}
}
If you swipe back and forth the text doesnt change. It should increase or decrease eg Slide 1, Slide 2 etc...
BUT do a few swipes and then instead of swiping just click down on the slide and move it a little and THEN the label does refresh to give you the correct value!
Its almost like because I am looping - all thats displayed is the original slide value and not the updated value, until I click somewhere on the slide causing it to refresh.
So bottom line I assume this is a bug?
Is there any way I can trigger this "refresh" behaviour programmatically?
Thanks
Hi change your code for home.page.html to:
<ion-slides loop="true" (ionSlidePrevEnd)="slideChanged(-1)" (ionSlideNextEnd)="slideChanged(1)">
<ion-slide *ngFor="let item of items">Slide {{newval}}
<ion-list>
{{item}}
</ion-list>
</ion-slide>
</ion-slides>
I have tested it in plunker and the content will change when you slide. Do ngFor for each ion-slide instead of within the ion-slide
Try this ionic 3
<ion-slides loop="true" autoplay="1" speed="6000">
<ion-slide>Slide A</ion-slide>
<ion-slide>Slide B</ion-slide>
<ion-slide>Slide C</ion-slide>
</ion-slides>

Google Line Chart with Javascript literal Datatablse now showing X-Axis

I am implementing a Google (line) Chart based on a DataTable so I can change the type of graph 'on the fly'. I have successfully generated the data table (generated by script) based on https://developers.google.com/chart/interactive/docs/reference#dataparam
And implemented in an HTML Page (for testing purpose the page is empty so there is no interference with any other script/content)
The Y-axis, Legenda and lines are correctly generated, yet the x-axis appears to be missing.
I am using the following content for the data table:
{"cols":[{"id":"timestamp","label":"timestamp","pattern":"","type":"string"},{"id":"sy","label":"sy","pattern":"","type":"number"},{"id":"us","label":"us","pattern":"","type":"number"},{"id":"average_cpu","label":"average_cpu","pattern":"","type":"number"}],"rows":[{"c":[{"v":"1372249356","f":""},{"v":0,"f":""},{"v":4,"f":""},{"v":43,"f":""}]},{"c":[{"v":"1372249650","f":""},{"v":13,"f":""},{"v":46,"f":""},{"v":49,"f":""}]},{"c":[{"v":"1372249950","f":""},{"v":4,"f":""},{"v":45,"f":""},{"v":47,"f":""}]},{"c":[{"v":"1372250250","f":""},{"v":2,"f":""},{"v":19,"f":""},{"v":46,"f":""}]},{"c":[{"v":"1372250550","f":""},{"v":3,"f":""},{"v":46,"f":""},{"v":51,"f":""}]}]}
This all comes together in the following Javascript
<html>
<head>
<!--Load the AJAX API-->
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script type="text/javascript">
// Load the Visualization API and the piechart package.
google.load('visualization', '1', {'packages':['corechart']});
</script>
<script type="text/javascript">
google.setOnLoadCallback(draw_15a6f1d2a7556b357de0d315596aa96c);
function draw_15a6f1d2a7556b357de0d315596aa96c() {
var data = new google.visualization.DataTable({"cols":[{"id":"timestamp","label":"timestamp","pattern":"","type":"string"},{"id":"sy","label":"sy","pattern":"","type":"number"},{"id":"us","label":"us","pattern":"","type":"number"},{"id":"average_cpu","label":"average_cpu","pattern":"","type":"number"}],"rows":[{"c":[{"v":"1372249356","f":""},{"v":0,"f":""},{"v":4,"f":""},{"v":43,"f":""}]},{"c":[{"v":"1372249650","f":""},{"v":13,"f":""},{"v":46,"f":""},{"v":49,"f":""}]},{"c":[{"v":"1372249950","f":""},{"v":4,"f":""},{"v":45,"f":""},{"v":47,"f":""}]},{"c":[{"v":"1372250250","f":""},{"v":2,"f":""},{"v":19,"f":""},{"v":46,"f":""}]},{"c":[{"v":"1372250550","f":""},{"v":3,"f":""},{"v":46,"f":""},{"v":51,"f":""}]}]});
var chart = new google.visualization.LineChart(document.getElementById('draw_15a6f1d2a7556b357de0d315596aa96c'));
chart.draw(data, {width: 800, height: 600});
}
</script>
</head>
<body>
<div id="draw_15a6f1d2a7556b357de0d315596aa96c"></div>
</body>
</html>
Yet I have no idea why the X-axis is not showing up. I have looked into the DataTable Roles but could not find a reference to show the X-axis
https://developers.google.com/chart/interactive/docs/roles?hl=ja#jsonliteral
Nor does the LineChart documentation say which additional arguments have to be supplied.
jsfiddle.net/WuLWF/ (When breaking it up in pieces according to Fiddle standard it did not work)
Or perhaps my DataTable is wrong generated.
Please guide me in the correct direction,
Many thanks
The x-axis is showing up but the labels are not showing up. Your first column is of type string, so you wouldn't see gridlines in any case, but for each row, the first column "f" property is an empty string, which means it will be displayed in the axis label as an empty string, just as it does.
I bet you did this so the tooltips would not show these same values. You might want to investigate custom tooltips to display whatever you want in the tooltips.
If you had used numbers instead of strings for the first column, then the axis labels would be generated and displayed as numbers, using the axis format option, and the values might happen to be close to the same values as in your first column. Discrete string values are used as is.
Or perhaps you would prefer to use a type of date, datetime, or timeofday. These are also treated as continuous, like numbers, rather than discrete, so the formatting of the tick labels is determined by the axis format option. Hope that helps.