简体   繁体   English

如何从Excel文件中以高图输入

[英]How to give input in highcharts from excel file

I want to give data input to highcharts from my excel file (info.xlsx). 我想从我的excel文件(info.xlsx)向highcharts输入数据。 I wrote a code in php which takes data from excel file and convert it to JSON, my php code is running perfectly and giving output in JSON format. 我用php写了一个代码,该代码从excel文件中获取数据并将其转换为JSON,我的php代码运行完美,并以JSON格式提供输出。 I want to give this input to highcharts and whenever I change data, it should update itself accordingly. 我想将此输入提供给图表,每当我更改数据时,它都应相应地进行更新。 I have seen demo chart from this source( http://www.highcharts.com/demo/pie-basic ). 我已经从这个来源( http://www.highcharts.com/demo/pie-basic )看了演示图表。 In this source developer has embedded sample data in code, I want to give data series from excel file. 在此源代码中,开发人员已将示例数据嵌入代码中,我想提供excel文件中的数据系列。 I am sharing my php file and js file. 我正在共享我的php文件和js文件。 I need suggestions. 我需要建议。

threeG.php // it takes xlsx file and produce its json threeG.php //它获取xlsx文件并生成其json

<?php
header('Cache-Control: no-cache, must-revalidate');
header("Expires: Sat,26 Jul 1997 05:00:00 GMT");
header('Content-type: application/json');
error_reporting(E_ALL);
ini_set('display_errors', TRUE);
ini_set('display_startup_errors', TRUE);
require_once('phpexcel/Classes/PHPExcel/IOFactory.php');
if(!file_exists("info.xlsx"))
{
    die("No File Exist");
}
$objPHPExcel = phpexcel_IOFactory::load("info.xlsx");
$objWorkSheet= $objPHPExcel->getActiveSheet();
define('Days',7);
$info=array();
$count=array();
$threeG_info= array($info,$count);
for ($col=0; $col < count($threeG_info); $col++)
{
    for ($row=1;$row<= Days+1;$row++)
    {
        $threeG_info[$col][$row-1]= $objWorkSheet-> getCellByColumnAndRow($col,$row)->getValue();
    }
}
echo json_encode($threeG_info);
?>

This is my js file. 这是我的js文件。 Where I want to give input, from my excel file. 我想在我的Excel文件中提供输入的地方。

$(function () {
    $('#container').highcharts({
        chart: {
            plotBackgroundColor: null,
            plotBorderWidth: 1,//null,
            plotShadow: false
        },
        title: {
            text: '3G Information'
        },
        tooltip: {
            pointFormat: '{series.name}: <b>{point.percentage:.1f}%</b>'
        },
        plotOptions: {
            pie: {
                allowPointSelect: true,
                cursor: 'pointer',
                dataLabels: {
                    enabled: true,
                    format: '<b>{point.name}</b>: {point.percentage:.1f} %',
                    style: {
                        color: (Highcharts.theme && Highcharts.theme.contrastTextColor) || 'black'
                    }
                }
            }
        },
        series: [{
            type: 'pie',
            name: 'Pie share',
            data: [

              **Want to give input here**
            ]
        }]
    });
});
$.ajax({
    url: "threeG.php",
    cache:false,
    type: 'json'
}).success(function(data)
{console.log(data);
}).error(function()
{
    alert('Error retrieving information');
});

Simply create chart inside callback for $.ajax() , like this: 只需在$.ajax()回调内部创建图表,如下所示:

$.ajax({
    url: "threeG.php",
    cache:false,
    type: 'json'
}).success(function(data) {
    $('#container').highcharts({
        // some options..
        series: [{
            data: data
        }]
    });
}).error(function(){
    alert('Error retrieving information');
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM