繁体   English   中英

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

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

我想从我的excel文件(info.xlsx)向highcharts输入数据。 我用php写了一个代码,该代码从excel文件中获取数据并将其转换为JSON,我的php代码运行完美,并以JSON格式提供输出。 我想将此输入提供给图表,每当我更改数据时,它都应相应地进行更新。 我已经从这个来源( http://www.highcharts.com/demo/pie-basic )看了演示图表。 在此源代码中,开发人员已将示例数据嵌入代码中,我想提供excel文件中的数据系列。 我正在共享我的php文件和js文件。 我需要建议。

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

这是我的js文件。 我想在我的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');
});

只需在$.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