Coudn't get result of highchart - php

I am using highchart, it gives result.
But, when I am going to make date range, nothing is happening and even my result goes blank!
I just want to find where I am wrong!
Here is my code:
<script type="text/javascript">
$(document).ready(function()
{
var options = {
chart:
{
renderTo: 'container',
type: 'column',
marginRight: 130,
marginBottom: 25
},
rangeSelector:
{
selected: 1,
inputDateFormat: '%Y-%m-%d',
inputEditDateFormat: '%Y-%m-%d'
},
title:
{
text: 'Project Requests',
x: -20 //center
},
subtitle:
{
text: '',
x: -20
},
xAxis:
{
categories: []
},
yAxis:
{
title:
{
text: 'Requests'
},
plotLines: [{
value: 0,
width: 1,
color: '#808080'
}]
},
tooltip:
{
formatter: function() {
return '<b>'+ this.series.name +'</b><br/>'+this.x +': '+ this.y;
}
},
legend:
{
layout: 'vertical',
align: 'right',
verticalAlign: 'top',
x: -10,
y: 100,
borderWidth: 0
},
series: []
}
$.getJSON("data", function(json)
{
options.xAxis.categories = json[0]['data'];
options.series[0] = json[1];
options.series[1] = json[2];
// options.series[2] = json[3];
chart = new Highcharts.StockCart(options);
});
function (chart)
{
setTimeout(function ()
{
$('input.highcharts-range-selector', $(chart.container).parent())
.datepicker({
format: "dd/mm/yyyy",
todayBtn: "linked",
orientation: "auto left",
autoclose: true,
todayHighlight: true
});
}, 0);
$.datepicker.setDefaults
({
dateFormat: 'yy-mm-dd',
onSelect: function (dateText) {
this.onchange();
this.onblur();
}
});
</script>
Here my Controller:
<?php
if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Chart extends CI_Controller
{
public function __construct()
{
parent::__construct();
$this->load->database();
$this->load->model('Data');
$this->load->helper('url');
}
public function index()
{
//echo "adsf";exit;
$this->load->view('allindex');
}
public function data()
{
$data = $this->Data->get_data();
$category = array();
$category['name'] = 'date';
$series1 = array();
$series1['name'] = 'employee_id';
$series2 = array();
$series2['name'] = 'customer_id';
// $series3 = array();
// $series3['name'] = 'sale_id';
foreach ($data as $row)
{
$category['data'][] = $row->date;
$series1['data'][] = $row->employee_id;
$series2['data'][] = $row->customer_id;
// $series3['data'][] = $row->sale_id;
}
$result = array();
array_push($result,$category);
array_push($result,$series1);
array_push($result,$series2);
// array_push($result,$series3);
print json_encode($result, JSON_NUMERIC_CHECK);
}
Here is Model:
<?php
class Data extends CI_Model
{
public function __construct()
{
parent::__construct();
}
public function get_data()
{
$this->db->select('date,sale_id,employee_id,customer_id');
$this->db->from('ospos_sales');
$this->db->where("`date` BETWEEN '2013-10-11' AND '2013-10-12'");
$query = $this->db->get();
return $query->result();
}
}

The only idea that there is a problem with dateFormat. Try to comment this lines
inputDateFormat: '%Y-%m-%d',
inputEditDateFormat: '%Y-%m-%d'
i have no more idea

Related

How do i get date and time in points highchart?

I plot highcharts on my page.
This works great but i have one little problem that in my points when i hover with my mouse on it, i get no date and time with it.
This is what my json is like.:
[{"metingen":"metingen","Datum":"Datum","data":["5-9-2022",14.6,"5-9-2022",14.8,"6-9-2022",15.948,"6-9-2022",17.112,"6-9-2022",
My chart look then like this.:
You see on the left the baloon, it show the number 0: 14.6.
14.6 is the value, thats good but the 0 is number of that value sutch as another point, that gives
But how can i show the date and time thats belong with that number in the baloon?
My chart code is this.:
$.getJSON("mfrmetingen300RG.json", function(data) {
const processedData9 = [];
for (let a = 0; a < data[0].data.length; a += 2) {
processedData9.push([data[0].data[a], data[0].data[a + 1]]);
}
data[0].data = processedData9;
avg = <?php echo $rowj[0]; ?>;
StDev = <?php echo $rowj[1]; ?>;
Aantalwaarden9 = <?php echo $rowj[2]; ?>;
//Cp=(USL-LSL)/(6xstd.Dev) see.:https://www.easycalculation.com/statistics/learn-cp-cpk-calculator.php
//Cpk = (USL-gemiddelde) / (3 x std.Dev) of (gemiddelde-LSL) / (3 x std.Dev)
cpkl1 = (<?php echo $_cpkh10waarde; ?>-<?php echo $_cpkl10waarde; ?>)/(6*StDev);
Cpk1High = (<?php echo $_cpkh10waarde; ?>-avg)/(3*StDev);
Cpk1Low = (avg-<?php echo $_cpkl10waarde; ?>)/(3*StDev);
chart9 = new Highcharts.Chart('container9',{
chart: {
zoomType: 'x',
type: 'line',
marginRight: 130,
marginBottom: 100,
backgroundColor:'azure'
},
rangeSelector: {
buttons: [{
text: '+',
events: {
click() {
return false
}
}
},
{
text: '-',
events: {
click() {
return false
}
}
}]
},
title: {
useHTML: true,
text: "Gemeten MFR waarde van PP 300R Grey Extrusie over de laatste "+(Aantalwaarden9)+" waarden.",
x: -20 //center
},
credits: {
enabled: false
},
subtitle: {text: 'Gem.='+avg.toFixed(2)+' Stdev='+StDev.toFixed(2)+' Cp='+cpkl1.toFixed(2)+' Cpk_High='+Cpk1High.toFixed(2)+' Cpk_Low='+Cpk1Low.toFixed(2)+'',x: -20},
xAxis: {
uniqueNames: false,
type: 'category',
title: {
text: 'Datum'
}
},
yAxis: {
"min":15,
"max":23,
title: {
text: 'MFR'
},
plotLines: [{
value: 0,
width: 1,
color: '#808080'
}],
plotLines: [{value: <?php echo $_cpkl10waarde; ?>,color: <?php echo $_color_min_line; ?>,dashStyle: 'longdashdot',width: 2,label: {text: 'Minimum'}},
{value: <?php echo $_cpkh10waarde; ?>,color: <?php echo $_color_max_line; ?>,dashStyle: 'longdashdot',width: 2,label: {text: 'Maximum'}},
{value: <?php echo $_cpkm10waarde; ?>,color: <?php echo $_color_guide_line; ?>,dashStyle: 'shortdash',width: 2,label: {text: 'Richtlijn'}},
{value: avg.toFixed(2),color: <?php echo $_color_avg_line; ?>,dashStyle: 'spline',width: 2,label: {text: 'Avg'}},
]
},
tooltip: {
formatter: function() {
return '<b>Meetwaarden</b><br/>'+ this.x +': '+ this.y;
}
},
legend: {layout: 'vertical',align: 'right',verticalAlign: 'top', x: -100,y: 0,floating: true,borderWidth: 0},
series: data,
plotOptions: {
line: {
dataLabels: {
enabled: true
}
}
},
});
chart9.legend.allItems[0].update({name:'MFR'});
}, 1000);
});```
Because you have category type xAxis, your category name is contained in point.key variable. So, based on your example, you only need to refer to this.key
tooltip: {
formatter: function() {
return '<b>Meetwaarden</b><br/>'+ this.key +': '+ this.y;
}
},
Simplified Demo:
https://jsfiddle.net/BlackLabel/87bousnL/
API Reference:
https://api.highcharts.com/highcharts/tooltip.headerFormat

not able to get the x axis and y -axis data or values from php array using canvaschart js using php

first page screen shots
second page screen shots
not able to display the x- axis and y-axis data from array in canvaschart js using php or zendframework and mysql
<?php
namespace Dashboard\Controller;
use Zend\Mvc\Controller\AbstractActionController;
use Zend\View\Model\ViewModel;
use Zend\Session\Container;
use Application\Entity\PyPayGroup;
use Application\Entity\PyPayPeriod;
use Zend\Session\SessionManager;
use Application\Entity\CommonCompanyHeader;
use Dashboard\Form\PayrollspendForm;
class PayrollspendController extends AbstractActionController
{
private $entityManager;
private $payrollspendManager;
private $sessionContainer;
private $pyPayPeriodClass;
private $pyPayGroupClass;
private $companyClass;
public function __construct($entityManager,$payrollspendManager)
{
$this->payrollspendManager = $payrollspendManager;
$this->entityManager = $entityManager;
$this->pyPayGroupClass = $this->entityManager->getRepository(PyPayGroup::class);
$this->pyPayPeriodClass = $this->entityManager->getRepository(PyPayPeriod::class);
$this->companyClass = $this->entityManager->getRepository(CommonCompanyHeader::class);
$sessionManager = new SessionManager();
$this->sessionContainer = new Container('ContainerNamespace', $sessionManager);
$arrLabel = ['payroll_calendar','label_payroll_group','emp_id','emp_name','label_total_earnings','label_payroll_period','company','label_process_id','session_id','label_employer_contribution','pay_item'];
}
public function addAction()
{
if ($this->sessionContainer->empId == "") {
return $this->redirect()->toRoute('admin_user_login');
}
if (!in_array('PY', $this->sessionContainer->arrRole)) {
if (!in_array('py_admin', $this->sessionContainer->arrRole)) {
return $this->redirect()->toRoute('dashboard_ess_index');
}
}
$reportForm = new PayrollspendForm();
$payGroup = $this->pyPayGroupClass->findBy([
'ouCode' => $this->sessionContainer->ouCode,
'langCode' => $this->sessionContainer->langCode,
'pgActive' => 1
]);
$reportForm->buildPayGroupData($payGroup);
$company = $this->companyClass->findBy([
'ouCode' => $this->sessionContainer->ouCode,
'langCode' => $this->sessionContainer->langCode
]);
$reportForm->buildCompanyData($company);
$payPeriodData = ['' => 'Select'];
$reportForm->get('payPeriod')->setValueOptions($payPeriodData);
$postData = $this->getRequest()->getPost()->toArray();
$postData['ouCode'] = $this->sessionContainer->ouCode;
$postData['langCode'] = $this->sessionContainer->langCode;
$compData = $this->payrollspendManager->buildCTCCompensationData($postData);
$groupByData = [
'' => 'Select',
'location' => 'Location',
'department' => 'Department',
'cost-center' => 'Cost center'
];
$reportForm->get('groupby')->setValueOptions($groupByData);
return new ViewModel([
'form' => $reportForm,
'ouCode' => $this->sessionContainer->ouCode,
'reportData' => $compData ,
'langCode' => $this->sessionContainer->langCode,
]);
}
This is model
public function getAllCTCCompensationData($postData)
{
$queryBuilder = $this->entityManager->createQueryBuilder();
$queryBuilder->select('ppp.payperiodSdesc , ppesa.grossPay, pptpp.pfEmployerContribution, pptpp.esiEmployerContribution, pplw.employercontribution')
->from(PyProcessEmpStatusApproved::class, 'ppesa')
->leftJoin(PyProcessTdsPfPt::class, 'pptpp', 'with', 'ppesa.ouCode = pptpp.ouCode')
->leftJoin(PyPayGroup::class, 'ppg', 'with', 'pptpp.pgCode = ppg.pgCode')
->leftJoin(PyProcessLabourWelfare::class, 'pplw', 'with', 'ppg.pgCode = pplw.pgCode')
->leftJoin(PyPayPeriod::class,'ppp','with','pplw.payperiodCode = ppp.payperiodCode')
->leftJoin(PyPayrollCalendar::class, 'ppc', 'with', 'ppp.paycalCode = ppc.paycalCode')
->where('ppesa.ouCode = ?1')
->andWhere('ppesa.langCode = ?2')
->setParameter('1', $postData['ouCode'])
->setParameter('2', $postData['langCode'])
->setMaxResults(60);
$compData = $queryBuilder->getQuery()->getResult();
$data = [];
if(!empty($compData))
{
$total = 0;
foreach($compData as $dataC)
{
$statData = $this->getStatuoryData($postData,$dataC['payperiodSdesc']);
if(isset($statData['payperiodSdesc']))
{
$data[$dataC['payperiodSdesc']]['PAYPERIOD'] = $this->payPERIODdata($postData,$dataC['payperiodSdesc']);
}
else
{
$data[$dataC['payperiodSdesc']]['PAYPERIOD'] = $this->payPERIODdata($postData,$dataC['payperiodSdesc']);
}
if(isset($statData['pfEmployerContribution']))
{
$data[$dataC['payperiodSdesc']]['PF'] = $this->getPFData($postData,$dataC['payperiodSdesc']);
}
else
{
$data[$dataC['payperiodSdesc']]['PF'] = $this->getPFData($postData,$dataC['payperiodSdesc']);
}
if(isset($statData['pfPensionFund']))
{
$data[$dataC['payperiodSdesc']]['PFF'] = $this->getPFData($postData,$dataC['payperiodSdesc']);
}
else
{
$data[$dataC['payperiodSdesc']]['PFF'] = $this->getPFData($postData,$dataC['payperiodSdesc']);
}
if(isset($statData['grossPay']))
{
$data[$dataC['payperiodSdesc']]['GROSS'] = $this->getGROSSPAYData($postData,$dataC['payperiodSdesc']);
}
else
{
$data[$dataC['payperiodSdesc']]['GROSS'] = $this->getGROSSPAYData($postData,$dataC['payperiodSdesc']);
}
if(isset($statData['employercontribution']))
{
$data[$dataC['payperiodSdesc']]['LABOURWELFARE'] = $this->getEMPLOYERCONTRIBUTIONData($postData,$dataC['payperiodSdesc']);
}
else
{
$data[$dataC['payperiodSdesc']]['LABOURWELFARE'] = $this->getEMPLOYERCONTRIBUTIONData($postData,$dataC['payperiodSdesc']);
}
if(isset($statData['esiEmployerContribution']))
{
$data[$dataC['payperiodSdesc']]['ESIC'] = $this->getESICData($postData,$dataC['payperiodSdesc']);
}
else
{
$data[$dataC['payperiodSdesc']]['ESIC'] = $this->getESICData($postData,$dataC['payperiodSdesc']);
}
$data[$dataC['payperiodSdesc']]['Total'] = $this->getCTCCompensationSum($postData,
isset($data[$dataC['payperiodSdesc']]['payperiodSdesc']),
isset($data[$dataC['payperiodSdesc']]['pfEmployerContribution']),
isset($data[$dataC['payperiodSdesc']]['pfPensionFund']),
isset($data[$dataC['payperiodSdesc']]['esiEmployerContribution']),
isset($data[$dataC['payperiodSdesc']]['grossPay']),
isset($data[$dataC['payperiodSdesc']]['employercontribution']));
$data = [$data[$dataC['payperiodSdesc']]['Total']];
}
}
return $data;
}
This is view file or canvaschartjs
<script>
window.onload = function () {
var chart1 = new CanvasJS.Chart("chartContainer1", {
animationEnabled: true,
title: {
text: ""
},
axisX: {
labelFontColor: "#000000",
labelFontStyle: "oblique",
},
axisY: {
title: "",
titleFontColor: "#4F81BC",
lineColor: "#4F81BC",
labelFontColor: "#4F81BC",
tickColor: "#4F81BC"
},
axisY2: {
title: "",
titleFontColor: "#C0504E",
lineColor: "#C0504E",
labelFontColor: "#C0504E",
tickColor: "#C0504E"
},
toolTip: {
shared: true
},
legend: {
cursor: "pointer",
itemclick: toggleDataSeries
},
data: [{
type: "column",
name: "Total",
legendText: "Total",
showInLegend: true,
dataPoints: [
<?php
echo '<pre>';
print_r($compData);
die;
if(!empty($compData))
{
?>
<?php
foreach($compData as $key => $value)
{
?>
{label: "<?php echo $key; ?>", y:<?php echo $value[$data[$dataC['payperiodSdesc']]['Total']]; ?>},
<?php } ?>
<?php } ?>
]
},
{
type: "column",
name: "Closed",
legendText: "Closed",
showInLegend: true,
dataPoints: [
<?php
if(!empty($compData))
{
?>
<?php
foreach($compData as $key => $value)
{
?>
{label: "<?php echo $key; ?>", y: <?php echo $value[$data[$dataC['payperiodSdesc']]['Total']]; ?>},
<?php } ?>
<?php } ?>
]
},
{
type: "column",
name: "Lapsed",
legendText: "Lapsed",
showInLegend: true,
dataPoints: [
<?php if(!empty($compData)) { ?>
<?php foreach($compData as $key => $value) { ?>
{label: "<?php echo $key; ?>", y: <?php echo $value[$data[$dataC['payperiodSdesc']]['Total']]; ?>},
<?php } ?>
<?php } ?>
]
}]
});
}
chart1.render();
}
</script>
<script>
window.onload = function () {
var chart1 = new CanvasJS.Chart("chartContainer1", {
animationEnabled: true,
title: {
text: ""
},
axisX: {
labelFontColor: "#000000",
labelFontStyle: "oblique",
},
axisY: {
title: "",
titleFontColor: "#4F81BC",
lineColor: "#4F81BC",
labelFontColor: "#4F81BC",
tickColor: "#4F81BC"
},
axisY2: {
title: "",
titleFontColor: "#C0504E",
lineColor: "#C0504E",
labelFontColor: "#C0504E",
tickColor: "#C0504E"
},
toolTip: {
shared: true
},
legend: {
cursor: "pointer",
itemclick: toggleDataSeries
},
data: [{
type: "column",
name: "Total",
legendText: "Total",
showInLegend: true,
dataPoints: [
<?php
echo '<pre>';
print_r($compData);
die;
if(!empty($compData))
{
?>
<?php
foreach($compData[0] as $key => $value)
{
?>
{label: "<?php echo $key; ?>", y:<?php echo $value[$data[$dataC['payperiodSdesc']]['Total']]; ?>},
<?php } ?>
<?php } ?>
]
},
{
type: "column",
name: "Closed",
legendText: "Closed",
showInLegend: true,
dataPoints: [
<?php
if(!empty($compData))
{
?>
<?php
foreach($compData[1] as $key => $value)
{
?>
{label: "<?php echo $key; ?>", y: <?php echo $value[$data[$dataC['payperiodSdesc']]['Total']]; ?>},
<?php } ?>
<?php } ?>
]
},
{
type: "column",
name: "Lapsed",
legendText: "Lapsed",
showInLegend: true,
dataPoints: [
<?php if(!empty($compData)) { ?>
<?php foreach($compData[2] as $key => $value) { ?>
{label: "<?php echo $key; ?>", y: <?php echo $value[$data[$dataC['payperiodSdesc']]['Total']]; ?>},
<?php } ?>
<?php } ?>
]
}]
});
function toggleDataSeries(e) {
if (typeof (e.dataSeries.visible) === "undefined" || e.dataSeries.visible) {
e.dataSeries.visible = false;
} else {
e.dataSeries.visible = true;
}
}
chart1.render();
}
</script>
I am trying to draw a barchart of months of x-axis and Total spend on y-axis in graph.In controller class the data which i m sending to the view is $compData = $this->payrollspendManager->buildCTCCompensationData($postData);
The x-axis will show the month ie $data[$dataC['payperiodSdesc']]['PAYPERIOD'] and y-axis will show the total spend ie $data[$dataC['payperiodSdesc']]['Total']. This month and total spend you will find in model.
Here i m using canvasjs using zendframework.Now my data ie $compData is send from controller to view file.This compData has 7 elements and i want to display the zero elemnet in y-axis and sixth element in x-axis.
for canvasjs refer to https://canvasjs.com website using php.
if anybody require more code ...will help you
what is the issue in the code?
The graph should have both x-axis and y-axis.
i m recieving the data in controller in the form of array($compData).
This array i m sending it to view.
Then the array goes in foreach loop and display the zero element from array on x axis and last field ie 6th element on y-axis.
i m displaying the data on x and y-axis dynamically using canvas
js chart.
how to display the graph using canvaschart js ?
if anybody not getting clear about question can ask more for clearty
i m trying to draw a barchart of months of x-axis and Total spend on y-axis in graph
.In controller class the data which i m sending to the view is $compData = $this->payrollspendManager->buildCTCCompensationData($postData);
THe x-axis will show the month ie $data[$dataC['payperiodSdesc']]['PAYPERIOD'] and y-axis will show the total spend ie $data[$dataC['payperiodSdesc']]['Total'] .This month and total spend you will find in model.
here i m using canvasjs using zendframework.Now my data ie $compData is send from controller to view file.This compData has 7 elements and i want to display the zero elemnet in y-axis and sixth element in x-axis.
for canvasjs refer to https://canvasjs.com website using php.
i want to display the PAYPERIOD which is the first array from details array and Total from Details which is last array

Pass php variable in bar graph with highcharts

I have a bar graph made with highcharts that display properly, data are from mysql table. I would like to pass value i mean : ($category['data'][] = $r['Assign_To']) in each bar as variable so that when i click on a bar this value contained in variable is taken to a new page in order to use it in that page. The exemple given in highcharts website doesn't fit me because i use data from table.
1- this is the graph
$(document).ready(function() {
var options = {
chart: {
renderTo: 'container',
type: 'bar'
},
title: {
text: 'EOP Postings Issues Chart',
x: -20 //center
},
credits: {
enabled: false
},
xAxis: {
categories: []
},
yAxis: {
min: 0,
title: {
text: 'Requests'
},
},
legend: {
layout: 'vertical',
align: 'right',
verticalAlign: 'top',
x: -10,
y: 100,
borderWidth: 0
},
series: []
}
$.getJSON("DataEobChart.php", function(json) {
options.xAxis.categories = json[0]['data'];
options.series[0] = json[1];
chart = new Highcharts.Chart(options);
});
});
DataEobChart.php
$dbc = #mysqli_connect('', '', '', '');
$query = mysqli_query($dbc, "select *, count(Assign_To) as count,Assign_To from claims_follow_up.eob_posting where Status='open' group by Assign_To order by count desc");
$category = array();
$category['name'] = 'Month';
$series1 = array();
$series1['name'] = 'Number of issues assigned';
while($r = mysqli_fetch_array($query)) {
$category['data'][] = $r['Assign_To'];
$series1['data'][] = $r['count'];
}
$result = array();
array_push($result,$category);
array_push($result,$series1);
print json_encode($result, JSON_NUMERIC_CHECK);
mysqli_close($dbc);
Add a new section to your HighCharts definition called plotOptions containing this code:
plotOptions: {
series: {
cursor: 'pointer',
point: {
events: {
click: function (event) {
var index = event.point.index;
var Assign_To = options.xAxis.categories[index];
alert(Assign_To);
location.href = "NewPage.php?AssignTo=" + Assign_To;
}
}
}
}
},
This provides a click event handler which will figure out which options.xAxis.categories[] item to use based on which bar was clicked. It will then alert the result and then take the user to a page called NewPage.php with a request string called AssignTo.

How can I extract data from php and mysql for column and spline chart in highchart

I try to make a combo chart of column with spline highchart. I want this type of chart from highcharts [link] http://jsfiddle.net/sunman/dwyNz/8/. But here is my problem is I want to show my dynamic data both spline and column chart which comes from data.php using json for data retrieve. But my graph will not show properly like this [link] http://jsfiddle.net/sunman/dwyNz/8/ .
I want this type of graph through my code.in spline line I want to show 'bsp values' from query1 and in column chart I want to facility rating. Here is my code where I extract data through json:-
data.php
$query1 = mysql_query("SELECT projects_detail.Project_name,superfac_rating.faci_total
FROM projects_detail LEFT OUTER JOIN superfac_rating
ON projects_detail.project_id= superfac_rating.project_id ");
$category = array();
$category['name'] = 'Project';
while($row1 = mysql_fetch_array($query1)) {
$category['data'][] = $row1['Project_name'];
$series1['data'][] = $row1['faci_total'];
}
$query2 = mysql_query("SELECT projects_detail.Project_name,superfac_rating.faci_total
FROM projects_detail LEFT OUTER JOIN superfac_rating
ON projects_detail.project_id= superfac_rating.project_id
LEFT OUTER JOIN cost ON gsuperfac_rating.project_id=cost.project_id ");
$series1 = array();
$series1['name'] = 'Project Name';
$series2 = array();
$series2['name'] = 'BSP VALUES';
while($row2 = mysql_fetch_array($query2)) {
$series1['data'][] = $row2['faci_total'];
$series2['data'][] = $row2['bsp'];
}
$result = array();
array_push($result,$category);
array_push($result,$series1);
array_push($result,$series1);
array_push($result,$series2);
print json_encode($result, JSON_NUMERIC_CHECK);
Here I am design for graph:
$(function () {
var chart;
$(document).ready(function() {
$.getJSON("data.php", function(json) {
$('#container').highcharts({
chart: {
zoomType: 'xy'
},
title: {
text: 'Project facility Rating'
},
subtitle: {
text: 'testing'
},
xAxis: [{
categories: []
}],
yAxis: [{ // Primary yAxis
labels: {
// format: '{value} Rs.',
style: {
color: Highcharts.getOptions().colors[1]
}
},
title: {
text: 'Bsp Cost',
style: {
color: Highcharts.getOptions().colors[1]
}
}
}, { // Secondary yAxis
title: {
text: 'Facility Rating',
style: {
color: Highcharts.getOptions().colors[0]
}
},
labels: {
//format: '{value} out of 100',
style: {
color: Highcharts.getOptions().colors[0]
}
},
opposite: true
}],
tooltip: {
shared: true
},
legend: {
layout: 'vertical',
align: 'left',
x: 120,
verticalAlign: 'top',
y: 100,
floating: true,
backgroundColor: (Highcharts.theme && Highcharts.theme.legendBackgroundColor) || '#FFFFFF'
},
series: json
});
});
});
});
so tell me why my json code not create a graph ..

Get stats and show it in chart - PHP/HighCharts

I have a table called "tracks",it looks like this:
id,
name,
url
hits
I have a pie charts, from highcharts, the code looks like this:
var chart;
$(document).ready(function() {
chart = new Highcharts.Chart({
chart: {
renderTo: 'chart',
plotBackgroundColor: null,
plotBorderWidth: null,
plotShadow: false
},
title: {
text: 'Where users came from, total'
},
tooltip: {
formatter: function() {
return '<b>'+ this.point.name +'</b>: '+ this.percentage +' %';
}
},
plotOptions: {
pie: {
allowPointSelect: true,
cursor: 'pointer',
dataLabels: {
enabled: false
},
showInLegend: true
}
},
credits: {
enabled: false
},
series: [{
type: 'pie',
name: 'Browser share',
data: [
['Firefox.com', 45.0],
['Default.com', 26.8],
['MSN', 12.8],
['Google.com', 8.5],
['Yahoo.com', 6.2],
['Others', 0.7]
]
}]
});
});
My question is, how can I get data from the "tracks" table (hits), and the (name) and output it in the pie chart like:
'name','hits'
And then, at last, convert # of hits, to %.
series: [{
type: 'pie',
name: 'Browser share',
data: [
<?php
$sql = 'select sum(hits) from tracks';
$result = mysql_query($sql);
$row = mysql_fetch_row($result);
$totalHits = $row[0];
$sql = 'select name, hits from tracks order by hits desc';
$result = mysql_query($sql);
$i = 0;
$totalOther = 0;
$maxSlices = 5;
$minPercent = 10;
while ($row = mysql_fetch_row($result))
{
$percent = row[1] / $totalHits * 100;
if (++$i <= $maxSlices && $percent >= $minPercent)
{
echo json_encode($row);
}
else
{
$totalOther += $row[1];
}
}
if ( $totalOther > 0 ) echo json_encode(array('Other', $totalOther));
?>
]
}]
if you want to refresh it thourgh ajax...
...
series: [{
type: 'pie',
name: 'Browser share',
data: getData(function(result) {return result;}),
...
and
function getData(setDataCallback)
{
$.getJSON('file.php', args, function(result) { // use of jquery for clarity.
setDataCallback(result);
});
}
in php you have to do a new file ('file.php') with the code shown in the first code block;
Simplest way is to query data from mySql and then sort it same as
[
['Firefox.com', 45.0],
['Default.com', 26.8],
['MSN', 12.8],
['Google.com', 8.5],
['Yahoo.com', 6.2],
['Others', 0.7]
]
Requires if you want to show chart just on page loading.
You can also use JSON.

Categories