how to reset the graph/chart after zoomin, pan using chartjs - php

I recently added zoom-in and pan functionality to my line chart. Now i want to add a reset button or something like that when pressed graph come back to normal position/shape. Currently i am drawing it for dynamic data which get updated every10 seconds.
ThankYou in advance.

Try chartjs-plugin-zoom
First, get the Chart.js instance, and then you can just call the resetZoom function of the instance to reset the zooming and panning.
window.myLine = new Chart(ctx, config);
...
function resetZoom() {
window.myLine.resetZoom();
}
...
<button onclick="resetZoom()">Reset Zoom</button>
The chart.js version I'm using is 2.9.3 and chartjs-plugin-zoom version 0.7.7
See examples:
chartjs-plugin-zoom samples
chartjs zoom and pan on codepen

There are multiple ways to do this:
Try any of these:
1. .clear()
2. .destroy()
myLineChart.destroy();
Then re-initialize the chart:
var ctx = document.getElementById("myChartLine").getContext("2d");
myLineChart = new Chart(ctx).Line(data, options);
delete the element and then reappending a new to the parent container
var resetCanvas = function () {
$('#results-graph').remove(); // this is my <canvas> element
$('#graph-container').append('<canvas id="results-graph"><canvas>');
canvas = document.querySelector('#results-graph');
ctx = canvas.getContext('2d');
ctx.canvas.width = $('#graph').width(); // resize to parent width
ctx.canvas.height = $('#graph').height(); // resize to parent height
var x = canvas.width/2;
var y = canvas.height/2;
ctx.font = '10pt Verdana';
ctx.textAlign = 'center';
ctx.fillText('This text is centered on the canvas', x, y);
};`
.update( )
Calling update() on your Chart instance will re-render the chart with any updated values, allowing you to edit the value of multiple existing points, then render those in one animated render loop.
Also refer:
How to clear a chart from a canvas so that hover events cannot be triggered?
chart.js load totally new data

Related

ChartJS Stacked Group with labels on each bars

I am totally lost on how to achieve this chartjs-plugin-datalabels with my json result
[
"[{\"label\":\"Meal\",\"value\":\"Rice\"},{\"label\":\"Location\",\"value\":\"VI\"},{\"label\":\"Payment\",\"value\":\"50k\"}]",
"[{\"label\":\"Meal\",\"value\":\"Beans\"},{\"label\":\"Location\",\"value\":\"VI\"},{\"label\":\"Payment\",\"value\":\"35k\"}]",
"[{\"label\":\"Meal\",\"value\":\"Rice\"},{\"label\":\"Location\",\"value\":\"Maryland\"},{\"label\":\"Payment\",\"value\":\"50k\"}]",
"[{\"label\":\"Meal\",\"value\":\"Bread\"},{\"label\":\"Location\",\"value\":\"Maryland\"},{\"label\":\"Payment\",\"value\":\"150k\"}]",
"[{\"label\":\"Meal\",\"value\":\"Rice\"},{\"label\":\"Location\",\"value\":\"Maryland\"},{\"label\":\"Payment\",\"value\":\"35k\"}]"
]
Ideally I want to show Meal has 3 Rice, 1 Beans, 1 Bread and same goes for Location and Payment
Any help or directly will greatly be appreciated
The correct method to use, in order to be able to draw another chart on the same canvas, is .destroy(). You must call it on the previously created chart object. You may also use the same variable for both charts
var grapharea = document.getElementById("barChart").getContext("2d");
var myChart = new Chart(grapharea, { type: 'bar', data: barData, options: barOptions });
myChart.destroy();
myChart = new Chart(grapharea, { type: 'radar', data: barData, options: barOptions })

remove pagination on google pie chart

i have following code to display pie chart.
<script>
google.charts.load('current', {'packages':['corechart']});
// Set a callback to run when the Google Visualization API is loaded.
google.charts.setOnLoadCallback(drawChart);
//google.charts.setOnLoadCallback(drawChartTwo);
//google.charts.setOnLoadCallback(drawChartThree);
// Callback that creates and populates a data table,
// instantiates the pie chart, passes in the data and
// draws it.
function drawChart() {
// Create the data table.
var data = google.visualization.arrayToDataTable([
['Type', 'Duration'],
<?php
foreach($val as $data){
echo "['".$data['type']."', ".$data['duration']."],";
}
?>
]);
// Set chart options
var options = {'title':'Duration Analysis',
'width':830,
'height':300,
'is3D': true,
pieSliceText : 'none',
};
// Instantiate and draw our chart, passing in some options.
var chart = new google.visualization.PieChart(document.getElementById('chart_div'));
chart.draw(data, options);
</script>
and its working fine. but, now when i see chart on my browser i see it like.
in the image i see list of values in pagination with 3 page. but i want it to display right side of my chart without pagination. any possibility to display 3 colomns instead of 3 pagination page??? Please help me.

Resize info window of google map V3

I am facing huge problem to solve info window size. I want to show a image block and some text information in info window but after place the content info window size increased i have read some threads but no luck with my code. Can any one help me to sort it out.
// Creating an object literal containing the properties
// we want to pass to the map
var options = {
zoom: 5,
center: new google.maps.LatLng(44.913990, 15.205078),
mapTypeId: google.maps.MapTypeId.ROADMAP ,
};
// Creating the map
var map = new google.maps.Map(document.getElementById("map"), options);
// Creating a LatLngBounds object
var bounds = new google.maps.LatLngBounds();
// Creating an array that will contain the coordinates
// for New York, San Francisco, and Seattle
var content = [];
var places = [];content.push('Some html');
places.push(new google.maps.LatLng(44.913990, 15.205078));
// Creating a variable that will hold
// the InfoWindow object
var infowindow;
// Looping through the places array
for (var i = 0; i < places.length; i++)
{
// Adding the markers
var marker = new google.maps.Marker({
position: places[i],
map: map,
icon: "/themes/garland/images/beach_icon_gmap.png"
// title: "Place number " + i
});
// Wrapping the event listener inside an anonymous function
// that we immediately invoke and passes the variable i to.
(function(i, marker) {
// Creating the event listener. It now has access to the values of
// i and marker as they were during its creation
google.maps.event.addListener(marker, "click", function() {
// Check to see if we already have an InfoWindow
if (!infowindow) {
infowindow = new google.maps.InfoWindow({
maxWidth: 20,
maxheight: 20
});
}
// Setting the content of the InfoWindow
infowindow.setContent(content[i]);
// Tying the InfoWindow to the marker
infowindow.open(map, marker);
});
})(i, marker);
// Extending the bounds object with each LatLng
bounds.extend(places[i]);
}
// Adjusting the map to new bounding box
// map.fitBounds(bounds)
Any help would be greatly appreciated. Thanks in advance.
The first thing I notice in your code: maxWidth is a valid property of the InfoWindowOptionsapi-doc object that is passed to the InfoWindow constructor, but maxheight is not. You won't be able to treat the InfoWindow as a strict or rigid container, although maxWidth will constrain the width. An InfoWindow is always sized to contain whatever content it has been provided. From the API Doc:
The InfoWindow will be sized according to the content. To set an
explicit size for the content, set content to be a HTML element with
that size.
That said, you are able to control the size, display, color, etc. of an InfoWindow by defining a CSS class and applying the styling rules to the content of the window. Taking the CSS approach to the content will pretty much give you complete control over the size of the content, because the InfoWindow just functions as a container for the content. If a CSS rule results in content of the correct size, your InfoWindow will be the correct size.

ExtJS 3.4 Slider Control

My question is releated to Extjs 3.4 Slider control. I want to get values i.e. min value and max value of two way slider on change event and dsiplay them in tag. But i cannot get two values for two different thumbs. In short i want get separate values of two thumbs. Here is my code
Ext.onReady(function(){
var tip = new Ext.slider.Tip({
getText: function(thumb){
if(thumb)
{
document.getElementById("lblAge").innerHTML= thumb.value;
}
}
});
new Ext.slider.MultiSlider({
renderTo: 'ageslider',
width : 124,
minValue: 0,
maxValue: 100,
values : [0, 90],
plugins : tip
});
I am not able to figure out the solution,Please check the code.
Thanks Inadvance.
there is a thumbs array in slider. You can make loop and get value for each thumb. Something similar:
getText: function(thumb){
var slider = thumb.slider;
values = [];
for (i = 0; i < slider.thumbs.length; i++) {
values.push(slider.thumbs[i].value);
}
console.log(values);
}

how to add/modify jQuery tooltip plugin for ajax - how to add live function?

I use this plugin for jQuery: http://bassistance.de/jquery-plugins/jquery-plugin-tooltip/
I would like add or modify this for add function live(), because now doesn't working with use Ajax.
all code:
http://pastebin.com/up6KYKCN
start in 47 line:
$.fn.extend({
tooltip: function(settings) {
settings = $.extend({}, $.tooltip.defaults, settings);
createHelper(settings);
return this.each(function() {
$.data(this, "tooltip", settings);
this.tOpacity = helper.parent.css("opacity");
// copy tooltip into its own expando and remove the title
this.tooltipText = this.title;
$(this).removeAttr("title");
// also remove alt attribute to prevent default tooltip in IE
this.alt = "";
})
.mouseover(save)
.mouseout(hide)
.click(hide);
},
probably here must change mouseover(save) and add live(), but how?
I assume you mean it doesn't work with the ASP.NET Ajax Toolkit?
If so I used Sys.Application.add_load() to attach my tooltips instead of jQuery $(document).ready().
The difference between the two is add_load is also called for partial postbacks (e.g. UpdatePanels) so your tooltips are reattached correctly.
See Dave Ward: $(document).ready() and pageLoad() are not the same!

Categories