Highcharts doesn't show if I pass parameters - php

I have a problem when I pass parameters with json_encode because I need to pass two arrays from php to javascript. My code run ok if i don't put the arrays
This is my javascript charts code:
function ChangeChartType(chart, series, newType) {
newType = newType.toLowerCase();
for (var i = 0; i < series.length; i++) {
var srs = series[0];
try {
srs.chart.addSeries({
type: newType,
stack: srs.stack,
yaxis: srs.yaxis,
name: srs.name,
color: srs.color,
data: srs.options.data
},
false);
series[0].remove();
} catch (e) {
}
}
}
// Two charts definition
var chart1, chart2;
// Una vez que el DOM (documento) ha acabado de cargar
$(document).ready(function() {
// First chart initialization
chart1 = new Highcharts.Chart({
chart: {
renderTo: 'chart_1',
type: 'column',
height: 350,
},
title: {
text: "<?php echo $titulo; ?>"
},
xAxis: {
categories: ['Processing.js', 'Impact.js', 'Other', 'Ease.js', 'Box2D.js', 'WebGL', 'DOM', 'CSS', 'Canvas', 'Javascript']
},
yAxis: {
title: {
text: 'Meses'
}
},
},function(chart){
//var i = 0;
for(i=0; i<3; i++) {
chart.addSeries({
data: [32, 43, 42],
index: 0,
zIndex:1
});
}
});
// Second chart initialization (pie chart)
chart2 = new Highcharts.Chart({
chart: {
renderTo: 'chart_2',
plotBackgroundColor: null,
plotBorderWidth: null,
plotShadow: false,
},
title: {
text: "<?php echo $titulo; ?>"
},
tooltip: {
formatter: function() {
var s;
if (this.point.name) { // the pie chart
s = ''+
this.point.name +': '+ this.y + ' totales';
} else {
s = ''+
this.x +': '+ this.y + ' totales';
}
return s;
}
//pointFormat: '{series.name}: <b>{point.percentage:.1f}%</b>'
},
plotOptions: {
pie: {
allowPointSelect: true,
cursor: 'pointer',
dataLabels: {
enabled: true,
color: '#000000',
connectorColor: '#000000',
format: '<b>{point.name}</b>: {point.percentage:.1f} %'
},
showInLegend: true
}
},
series: [{
type: 'pie',
name: 'Resultado',
data: [<?php echo $resultado ?>]
}]
});
// Switchers (of the Chart1 type) - onclick handler
$('.switcher').click(function () {
var newType = $(this).attr('name');
ChangeChartType(chart1, chart1.series, newType);
});
});
I open both charts with a dialog window
$(function() {
$( "#dialog1" ).dialog({
autoOpen: false,
width: 950,
height: 460,
show: {
effect: "blind",
duration: 1000
},
hide: {
effect: "blind",
duration: 1000
}
});
$( "#dialog2" ).dialog({
autoOpen: false,
width: 650,
height: 760,
show: {
effect: "blind",
duration: 1000
},
hide: {
effect: "blind",
duration: 1000
}
});
$( "#opener1" ).click(function() {
$( "#dialog1" ).dialog( "open" );
});
$( "#opener2" ).click(function() {
$( "#dialog2" ).dialog( "open" );
});
});
The problem is when i try add this arrays to add months and names instead of ['Processing.js', 'Impact.js', 'Other', 'Ease.js', 'Box2D.js', 'WebGL', 'DOM', 'CSS', 'Canvas', 'Javascript'] and default names
// Two charts definition
var chart1, chart2;
// Una vez que el DOM (documento) ha acabado de cargar
$(document).ready(function() {
var nombres = <?php echo json_encode($names); ?>; //I CAN'T SEE MY FIRST PIE CHART
var meses = <?php echo json_encode($valorX); ?>; //WHEN I INSERT BOTH VARIABLES
// First chart initialization
chart1 = new Highcharts.Chart({
chart: {
renderTo: 'chart_1',
type: 'column',
height: 350,
},
My portion of php
$valorX = array('Enero', 'Febrero', 'Marzo', 'Abril', 'Mayo', 'Junio', 'Julio', 'Agosto', 'Septiembre', 'Octubre', 'Noviembre', 'Diciembre');
$names = array('Ana', 'Elena', 'Juan');
So, I don't know what i did wrong. With only these arrays declared, my second chart (Pie chart) doesn't appear. My code is under construction. Sorry my bad english, coding and Thanks you very much!!!!!!

Related

How to show multiple highcharts on selection of few parameters and dynamically load JSON data using PHP page?

I have two parameters to load dynamic json data from mysql and visualise multiple line charts on page submit.
$.ajax({
url: 'get_pubmedid.php',
type: 'get',
data: {org: org, ptype: ptype, path: path,mirna: mirna},
dataType: 'json',
success:function(response) {
var len = response.length;
for( var i = 0; i<len; i++) {
pubmed = response[i]['name'];
cell=response[i]['cell'];
alert(cell+" "+pubmed+" "+len);
var cells=encodeURIComponent(cell);
var cname="charts"+(i+1);id=i+1;var pid=i+1;
var container = cname;
var func_name = cname;
func_name = function () {
Highcharts.chart(container, {
showhighcharts(org,ptype,path,mirna,cell,cells,pid,pubmed,cname,id);
}
}
func_name()
}
}
});
function showhighcharts(org,ptype,path,mirna,cell,cells,pid,pubmed,cname,id) {
$("#"+cname).html("Wait, Loading graph...");
var options = {
chart: {
type: 'line',
renderTo: cname
},
colors: ['#058DC7', '#50B432', '#ED561B', '#DDDF00', '#24CBE5', '#64E572', '#FF9655', '#FFF263', '#6AF9C4'],
credits: {
enabled: false
},
title: {
text: 'Temporal Viewer',
x: -20
},
xAxis: {categories:<?php //echo $_SESSION["cat"]; ?>,
offset:2,
title: {enabled: true,text: 'Time Point' }
},
tooltip: {
shared: true,
useHTML: true,
headerFormat: '<b>Time Point:{point.key}</b> <table style="width:200px;font-size:12px;font-weight:bold;">',
pointFormat: '<tr><td>Dosage:</td><td style="color: {series.color}">{series.name} </td></tr>' + '<tr><td>Fold Change:</td><td style="color: {series.color}">{point.y} </td></tr>',
footerFormat: '</table>',
enabled: true,
crosshairs: {
color: 'light gray',
dashStyle: 'longdash'
}
},
plotOptions: {
series: {
dashStyle: 'longdash'
},
line: {
dataLabels: {
enabled: true
},
enableMouseTracking: true
}
},
series: [{}]
};
$.ajax({
url: "jdatas.php?org="+org+"&ptype="+ptype+"&path="+path+"&mirna="+mirna+"&pid="+id+"&cell="+cell+"&pub="+pubmed,
data: 'show=impressions',
type:'get',
dataType: "json",
success: function(data){
var getSeries = data;
options.series = getSeries;
var chart1 = new Highcharts.Chart(options);
}
});
I want multiple graphs to be loaded on submit.
But its not showing any graph.

How to add php data into highchart js file in php

my code:
series: [{
name: 'Brands',
colorByPoint: true,
<?php
$models="SELECT * FROM purchase_info GROUP BY model_name";
$models_querry=mysql_query($models);
while($models_data=mysql_fetch_assoc($models_querry))
{
$model_name[]=$models_data['model_name'];
}
?>
data: [{
name: ['<?php echo join($model_name, ',') ?>'],
y: 56.33,
drilldown: 'Hero Honda'
}]
}],
In my project i'm using high charts, in that how can i add php data into that, i just collect all data and saved into one variable named as $model_name[], after that i pass the array value into data, but in that it will not spitted, all data's are echoed into single one.
Use ajax for that..see the script code
$.ajax({
type: "POST",
url: 'ajax.php',
success: function(data) {
a = jQuery.parseJSON(data);
i=0;
$.each( a.total_potential_score, function( key, val ) {
data1[i] = parseFloat(val);
i++;
});
rasterize_function(data1);
}
});
Ajax file look like this
$a[0] = "1";
$a[1] = "2";
$a1['total_potential_score'][0] = "1";
$a1['department_name'][0] = "aaaaa";
$a1['total_potential_score'][1] = "3";
$a1['department_name'][1] = "bbbbb";
echo json_encode($a1);
function for the highchart displayed here
function rasterize_function(data1) {
var seriesArray = [];
$.each( data1, function( key, val ) {
seriesArray.push({
name: "aaaa",
data: [val],
animation: false,
dataLabels: {
enabled: true,
rotation: -90,
color: '#FFFFFF',
align: 'right',
x: 4,
y: 10,
style: {
fontSize: '13px',
fontFamily: 'Verdana, sans-serif'
}
}
});
});
$('#container').highcharts({
chart: {
type: 'column',
width: 700,
height: 400,
borderWidth: 0
},
title: {
text: 'sector',
align: 'left'
},
subtitle: {
text: ''
},
xAxis: {
categories: ['College, Personal Development and Career Scores'],
},
yAxis: {
min: 0,
title: {
text: 'Potential Score'
}
},
legend: {
layout: 'horizontal',
backgroundColor: '#FFFFFF',
verticalAlign: 'bottom',
x: 10,
y: 7,
floating: false,
shadow: true
},
tooltip: {
formatter: function() {
return ''+
this.x +': '+ this.y +' points';
}
},
plotOptions: {
column: {
animation: false,
pointPadding: 0.2,
borderWidth: 0
}
},
series:seriesArray
});
}

HighCharts with JSON Data from multiple php files

I am new to HighCharts. I am making a pie chart with the data (JSON) coming form multiple php files. So i have used nested ajax calls. But I am stuck at how to integrate it into the chart data.
$.getJSON("php/footprint1.php", function(data1) {
$.getJSON("php/footprint2.php", function(data2) {
$.getJSON("php/footprint3.php", function(data3) {
$.getJSON("php/footprint4.php", function(data4) {
$.getJSON("php/footprint5.php", function(data5) {
$.getJSON("php/footprint6.php", function(data6) {
chart.series[0].data[0][1] = data1.reponse.numFound;
});
});
});
});
});
});
The chart goes like this.
chart = new Highcharts.Chart({
chart: {
renderTo: 'place2',
type: 'pie'
},
title: { align: 'center', text: 'Foot-Prints Detected' },
plotOptions: {
pie: {
shadow: false,
center: ['50%', '50%']
}
},
legend: {
enabled: true,
layout: 'vertical',
align: 'right',
width: 250,
verticalAlign: 'middle',
useHTML: true,
},
tooltip: {
formatter: function() {
return '<b>'+ this.point.name +'</b>: '+ this.y +' %';
}
},
series: [{
name: 'Browsers',
data: [["BLOG",4],["PAID",4],["DIRECTORY",9],["WORDPRESS",7],["ADULT",7],["PHARMACEUTICALS",8]],
size: '100%',
innerSize: '75%',
showInLegend:true,
dataLabels: {
enabled: true,
formatter: function() {
return Math.round(this.percentage*100)/100 + ' %';
},
distance: -25,
color:'black'
}
}],

highchart Dynamically updated data

i want to set up highcharts.
i made a simple random number in this url
http://echocephe.com/new/custom_number.php
i want to use these random datas on Dynamically updated data charts
this is code can you help me to solve this problem thanks.
<script type="text/javascript">
$(function () {
$(document).ready(function() {
Highcharts.setOptions({
global: {
useUTC: false
}
});
var chart;
$('#container').highcharts({
chart: {
type: 'spline',
animation: Highcharts.svg, // don't animate in old IE
marginRight: 10,
events: {
load: function() {
// set up the updating of the chart each second
var series = this.series[0];
setInterval(function() {
var x = (new Date()).getTime(), // current time
y = Math.random();
series.addPoint([x, y], true, true);
}, 1000);
}
}
},
title: {
text: 'Live random data'
},
xAxis: {
type: 'datetime',
tickPixelInterval: 150
},
yAxis: {
title: {
text: 'Value'
},
plotLines: [{
value: 0,
width: 1,
color: '#808080'
}]
},
tooltip: {
formatter: function() {
return '<b>'+ this.series.name +'</b><br/>'+
Highcharts.dateFormat('%Y-%m-%d %H:%M:%S', this.x) +'<br/>'+
Highcharts.numberFormat(this.y, 2);
}
},
legend: {
enabled: false
},
exporting: {
enabled: false
},
series: [{
name: 'Random data',
data: (function() {
// generate an array of random data
var data = [],
time = (new Date()).getTime(),
i;
for (i = -19; i <= 0; i++) {
data.push({
x: time + i * 1000,
y: Math.random()
});
}
return data;
})()
}]
});
});
});
</script>
maybe its better to check highchart forums
here is the answer
http://www.highcharts.com/docs/working-with-data/preprocessing-live-data/

Highcharts Pie Chart from Ajax

I have a page that uses highcharts pie chart, and I am trying to update the chart with a date selector drop down. I have a similar implementation for a bar chart and its working great. Please note (this is coming from a PHP class, hence the concatenation and what not).
<script type='text/javascript'>
function drawPie(data)
{
var chart;
alert('called');
var options = {
chart: {
renderTo: 'PieChart',
plotBackgroundColor: null,
plotBorderWidth: null,
plotShadow: false,
height: 350
},
title: {
text: 'Product Popularity'
},
tooltip: {
pointFormat: '{series.name}: <b>{point.percentage}%</b>',
percentageDecimals: 1
},
plotOptions: {
pie: {
allowPointSelect: true,
cursor: 'pointer',
dataLabels: {enabled: false},
showInLegend: true
}
},
series: [{
type: 'pie',
name: 'Product Popularity',
data: data
}]
}
chart = new Highcharts.Chart(options);
$('#ProductPieMod div.mod_content').css('height', $('#PieChart').css('height'));
}
$(document).ready(function(){
drawPie(" . $this->get_data($this->date) . ");
$('#ProductPieMod_date').on('change', function(){
var val = parseInt($(this).val());
switch(val)
{
case 0:
var date = Date.today();
break;
case 1:
var date = Date.parse('last week');
break;
case 2:
var date = Date.today().moveToFirstDayOfMonth();
break;
case 3:
var date = Date.parse('January').moveToFirstDayOfMonth();
break;
default:
var date = Date.today();
}
var info;
$.ajax({
type: 'POST',
url: '". matry::base_to('utilities/dhs/manager_dash') . "',
async: false,
dataType: 'json',
data: {date: date.toString('M/dd/yyyy'), module: 'ProductPieMod'},
success: function(data)
{
drawPie(data);
}
});
});
});
</script>
My ajax returns the following string:
[['FASTCLIX LANCING DEVICE', 62.5],['FREESTYLE LANCING DEVICE', 25],['ONETOUCH DELICA LANCING DEVICE', 12.5]]
In addition, this chart is initially built, using the exact same method, just fine. Its just when I use the dropdown (run the onChange event) that it breaks.
Update
I have created a fiddle for this as well: http://jsfiddle.net/SHReZ/1/
Firts, you need to place chart var to document.ready handler scope, next, you need to destroy chart before draw.
$(document).ready(function () {
var chart;
function drawPie(data) {
console.log('called');
var options = {
chart: {
renderTo: 'PieChart',
plotBackgroundColor: null,
plotBorderWidth: null,
plotShadow: false,
height: 350
},
title: {
text: 'Product Popularity'
},
tooltip: {
pointFormat: '{series.name}: <b>{point.percentage}%</b>',
percentageDecimals: 1
},
plotOptions: {
pie: {
allowPointSelect: true,
cursor: 'pointer',
dataLabels: {
enabled: false
},
showInLegend: true
}
},
series: [{
type: 'pie',
name: 'Product Popularity',
data: data
}]
};
if (chart !== undefined) chart.destroy();
chart = new Highcharts.Chart(options);
$('#ProductPieMod div.mod_content').css('height', $('#PieChart').css('height'));
}
drawPie([
['ONETOUCH DELICA LANCING DEVICE', 27.78],
['FREESTYLE LANCING DEVICE', 20.83],
['Nova Max Ketone Test Strips Health and', 11.11],
['ONETOUCH ULTRASOFT LANCING DEVICE 2PK', 11.11]
]);
//get data from https://gist.github.com/zba/4712055 , delay 4
$.post('/gh/gist/response.html/4712055', {
delay: 4
}, function (data) {
drawPie(data);
}, 'json');
});
fiddle
also here is demo which not destroy chart, but it change colors to much

Categories