Google scatter chart for two arrays - php

Hello People here is my Google scattered chart code what I am using:
require '/lib/GoogleChart.php';
require '/lib/markers/GoogleChartShapeMarker.php';
require '/lib/markers/GoogleChartTextMarker.php';
$Variance=array();
$Emp_RecFactor=array();
$Emp_Id=array();
//$Emp_FirstName=array();
$EquityGraph=new EquityGraph();
$EquityGraph->Graph();
$DrawGraph=$EquityGraph->DrawGraph;
foreach($DrawGraph as $key=>$value)
{
$Variance[]=$value["Variance"];//for multiple values ,array
$Emp_RecFactor[]=$value["Emp_RecFactor"];//single value
$Emp_Id[]=$value["Emp_Id"];//single value
}
$_GET['Variance']=$Variance;
$_GET['Emp_RecFactor']=$Emp_RecFactor;
print_r($Emp_RecFactor);
$chart = new GoogleChart('lc', 500, 200);
// manually forcing the scale to [0,100]
$chart->setScale(0,100);
// add one line
$data = new GoogleChartData($Variance);
$chart->addData($data);
// customize y axis
$y_axis = new GoogleChartAxis('y');
$y_axis->setDrawTickMarks(false)->setLabels(array(-5,0,5));
$chart->addAxis($y_axis);
// customize x axis
$x_axis = new GoogleChartAxis('x');
$x_axis->setTickMarks(5);
$chart->addAxis($x_axis);
// add a shape marker with a border
$shape_marker = new GoogleChartShapeMarker(GoogleChartShapeMarker::CIRCLE);
$shape_marker->setSize(6);
$shape_marker->setBorder(2);
$shape_marker->setData($data);
$chart->addMarker($shape_marker);
// add a value marker
$value_marker = new GoogleChartTextMarker(GoogleChartTextMarker::VALUE);
$value_marker->setData($data);
$chart->addMarker($value_marker);
//~ header('Content-Type: image/png');
echo $chart->toHtml();
As you can see in the code I have used $Variance array passing to $data now I need to use one more array $Emp_RecFactor and I need to draw a graph between those two...
I also want to add mouse over feature to this so that if someone hovers over the selected point it should display different things for different selected points -how do I do that?

To draw a Google scattered chart between two arrays you have to use code as below
var data = google.visualization.arrayToDataTable([
['Age', 'Array1', 'Array2'],
[8, 12, 15],
[4, 5.5, 0],
[11, 0, 14],
[4, 9, 5],
[3, 3.5, 9],
[6.5, 7, 13]
]);
And it has a default tooltip to show the data while hovering the selected point. We can also customize Tooltip content by using html tags.
To view a working sample for this go to the site jqfaq.com(Sample) and a customization of Tooltip content go to the site jqfaq.com(customizing Tooltip)

Related

How do I get the correct format x-axis for my phpspreadsheet chart?

I am using 33_Chart_create_scatter.php to make a two line xyScatter chart. Everything is going well, except, the x-axis is not formatting as I would like it to. There is no associated error involver. Only a poor x-axis. See the first image. For the correct (desired) x-axis, see the second image. Can someone help me achive the proper x-axis format?
I got the correct format x-axis by simply right clicking the chart area and selecting "Change Chart Type". Then I select (already selected) "X Y (Scatter)" and "ok". The x-axis is changed to that shown in my correct x-axis image. So, that brings about my second question, if I can not get a code correction to get the proper x-axis format, can we include macro's in our create charts? A simple three line auto_open macro included will yield the proper chart/x-axis when the new spreadsheet is opened.
I've used both horizontal and vertical selections for source values. I've also tried using specific values for the source. See J1:R1 in my image. I can not figure out how to add my images. So, incorrect x-axis runs from 1 to about 50 by 1's And it looks like there maybe two to three sets of numbers all crunched together. The correct scale is 0 to 40 by 5's evenly spaced. this is a minutes scale. The y scale looks perfect.
Here is the code involved.
$xAxisTickValues = [
new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_NUMBER, 'Worksheet!$C$1:$C$18', null, 18),
new
DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_NUMBER, 'Worksheet!$F$1:$F$18', null, 18)
];
The following code should control the x and y properties. I am able to control all the properties of the Y-axis. How ever it appears the x-axis min and max values are controlled by the x Axis Tick Values. If I don't use x Axis Tick Values, It then appears x-axis min and max values are controlled by the number of y data points?
What do I have to do so this code can be used to control x-axis min and max values?
$xaxis = new Axis();
$xaxis->setAxisOptionsProperties('low', 0, 'autoZero', null, 'in', 'out', 0, 40, 5, 0);
$title = new Title('Calorimetric Calibration');
$yAxisLabel = new Title(html_entity_decode('Temp (°C)',ENT_QUOTES,'UTF-8'));
$xAxisLabel = new Title('Time (Min)');
// Create the chart
$chart = new Chart(
'chart1', // name
$title, // title
$legend, // legend
$plotArea, // plotArea
true, // plotVisibleOnly
0, // displayBlanksAs
$xAxisLabel, // xAxisLabel
$yAxisLabel, // yAxisLabel
$yaxis,
$xaxis,
null,
null
);

getImageURI() returning a big url that won't open in browser

I'm currently converting my google column chart into a png, and then getting the url using chart_div.innerHTML, paste it into browser (Firefox).
My error is : 413. That’s an error. Your client issued a request that was too large
Is there any way to reduce the size of the url ? or any possible solution around it ? my goal is to be able to convert all of my 4 charts to pngs and print each, or at least 1.
send the image to a new window,
this will allow you to right click and save as, print, etc...
window.open(chart.getImageURI(), '_blank');
the above creates a "pop-up" and may be blocked,
you can also change the location of the current page...
location.href = chart.getImageURI();
see following fiddle for an example...
https://jsfiddle.net/7qtuhwaw/
EDIT
an option for chrome is to create a download link,
see following working snippet...
google.charts.load('current', {
callback: function () {
var data = new google.visualization.DataTable();
data.addColumn('date', 'Date');
data.addColumn('number', '2015');
data.addColumn('number', '2016');
data.addRows([
[new Date('01/01/2016'), 200, 210],
[new Date('02/01/2016'), 190, 220],
[new Date('03/01/2016'), 205, 200],
[new Date('04/01/2016'), 220, 230],
[new Date('05/01/2016'), 212, 210],
[new Date('06/01/2016'), 185, 193],
[new Date('07/01/2016'), 196, 207]
]);
var chart = new google.visualization.LineChart(document.getElementById('chart_div'));
google.visualization.events.addListener(chart, 'ready', function () {
downloadLink = document.createElement('a');
downloadLink.href = chart.getImageURI();
downloadLink.download = 'chart.png';
downloadLink.click();
});
chart.draw(data, {
hAxis: {
format: 'MMM'
},
height: 400
});
},
packages: ['corechart']
});
<script src="https://www.gstatic.com/charts/loader.js"></script>
<div id="chart_div"></div>
<div id="image_div"></div>
Example solution from google developpers as seen on the issues page of google charts.
Links:
Tutorial : https://developers.google.com/chart/interactive/docs/printing
Unless you have access to Google Servers, you will need to grab the charts in chunks. HTTP 413 means that the server declined your request, because it's just too big. Try splitting your chart into multiple charts and then either put it back together locally or just display the chunks.

post to textfield using tcpdf

I am unsure if I am going about this correctly. Why using TCPDF when I attempt to post it returns an empty textfield?
$pdf->Cell(35, 5, 'Job Number ');
$pdf->TextField($_POST["jobnum"], 50, 5);
You need to use the fourth $opt parameter see the TCPDF TextField reference and Acrobat API Reference
$pdf->TextField("jobnum", 50, 5, array(), array('v'=>$_POST["jobnum"] ) );
TCPDF requires the TextField() function to be like so: TextField("string", number, number)
so you need to make it like this:
$pdf->TextField("'".$_POST["jobnum"]."'", 50, 5);

Show country names on hover for dataless countries in Google GeoChart

I'm using Google GeoChart to show how many orders we have had from different countries for a particular month. With the data I'm feeding it, I've got it working all correctly.
However, what I would like to know is if there is a way to show the country name on hover on those that are dataless.
For example, here's some sample data I have:
function drawMap() {
var mapdata = google.visualization.arrayToDataTable([
['Country', 'Orders'],
['United Kingdom', 20],
['Ireland', 10],
['France', 3],
['Spain', 3],
['Germany', 2],
['Norway', 1],
['Sweden', 1]
]);
var mapoptions = {
width: 980,
colorAxis: {minValue: 0, colors: ['#6ED0DF', '#3266CC']}
}
var mapchart = new google.visualization.GeoChart(document.getElementById('mapchart'));
mapchart.draw(mapdata, mapoptions);
}
As you can see from my sample data, I've got data for a number of European countries so when the map is rendered on the screen, it will show the country name when you hover over those above. However, when I hover over Belgium or Poland (for example), the map doesn't show the name of the country.
Is there a way to show this? Ideally, I don't want to list ALL countries in mapdata - is there a function I can run that will show the other countries names? Even if it has to say 0 or N/A for the data...
Just for reference, I'm using PHP to get the data we need to populate the map from a MySQL database.

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);
}

Categories