Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/250.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ember.js/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 图表未正确呈现_Php_Phpexcel - Fatal编程技术网

Php 图表未正确呈现

Php 图表未正确呈现,php,phpexcel,Php,Phpexcel,我有一张小桌子 并希望使用PHPExcel库创建一个TYPE\u DONUTCHART。我从文件中提取了示例代码,并相应地对其进行了修改: $dataseriesLabels2 = array( //new PHPExcel_Chart_DataSeriesValues('String', 'Summen!$A$1', NULL, 1), ); $xAxisTickValues2 = array( new PHPExcel_Chart_DataSeriesValues('Str

我有一张小桌子

并希望使用PHPExcel库创建一个
TYPE\u DONUTCHART
。我从文件中提取了示例代码,并相应地对其进行了修改:

$dataseriesLabels2 = array(
    //new PHPExcel_Chart_DataSeriesValues('String', 'Summen!$A$1', NULL, 1),
);
$xAxisTickValues2 = array(
    new PHPExcel_Chart_DataSeriesValues('String', 'Summen!$B$1:$C$1', NULL, 2),
);
$dataSeriesValues2 = array(
    new PHPExcel_Chart_DataSeriesValues('Number', 'Summen!$B$2:$C$2', NULL, 2),
);
该文件由脚本提供服务,但当我尝试打开它时,会出现错误消息:

我们发现“Myfile.xlsx”中的某些内容存在问题。你想让我们尽力恢复吗?如果您信任此工作簿的来源,请单击“是”

当我单击“是”并激活文档编辑时,会收到如下消息:

Excel已完成对文件的检查和修复。此文件的某些部分已被修复或丢弃

删除的部分:part/xl/drawings/drawing4.xml。(图纸格式)

我的代码出了什么问题?我必须修改什么

注:

  • 如您所见,我使用的是另一个数据集,而不是示例中的数据集。只有范围
    A1:C2
    中的数据(参见上面的屏幕截图)
  • 工作表的名称是
    Summen
    ,我仔细检查了一下,问题不是工作表的打字错误
  • 有人在评论中询问了它,我已经尝试从
    dataseriesLabels2
    条目中删除该评论
    • 我的例子

      $objPHPExcel = new PHPExcel();
      $objWorksheet = $objPHPExcel->getActiveSheet();
      $objWorksheet->fromArray(
          array(
              array('Whatever', 'Cat1', 'Cat2'),
              array(77,         247,    128),
          )
      );
      $objWorksheet->setTitle('Summen');
      
      $dataSeriesLabels1 = array(
      //    new PHPExcel_Chart_DataSeriesValues('String', 'Summen!$A$1', NULL, 1),
      );
      
      $xAxisTickValues1 = array(
          new PHPExcel_Chart_DataSeriesValues('String', 'Summen!$B$1:$C$1', NULL, 2),
      );
      
      $dataSeriesValues1 = array(
          new PHPExcel_Chart_DataSeriesValues('Number', 'Summen!$B$2:$C$2', NULL, 2),
      );
      
      $series1 = new PHPExcel_Chart_DataSeries(
          PHPExcel_Chart_DataSeries::TYPE_DONUTCHART, // plotType
          NULL,                           // plotGrouping
          range(0, count($dataSeriesValues1)-1),      // plotOrder
          $dataSeriesLabels1,             // plotLabel
          $xAxisTickValues1,              // plotCategory
          $dataSeriesValues1              // plotValues
      );
      
      $layout1 = new PHPExcel_Chart_Layout();
      $layout1->setShowVal(TRUE);
      $layout1->setShowPercent(TRUE);
      
      $plotArea1 = new PHPExcel_Chart_PlotArea($layout1, array($series1));
      $legend1 = new PHPExcel_Chart_Legend(PHPExcel_Chart_Legend::POSITION_RIGHT, NULL, false);
      $title1 = new PHPExcel_Chart_Title('Test Pie Chart');
      
      
      $chart1 = new PHPExcel_Chart(
          'chart1',       // name
          $title1,        // title
          $legend1,       // legend
          $plotArea1,     // plotArea
          true,       // plotVisibleOnly
          0,          // displayBlanksAs
          NULL,       // xAxisLabel
          NULL        // yAxisLabel       - Pie charts don't have a Y-Axis
      );
      
      //  Set the position where the chart should appear in the worksheet
      $chart1->setTopLeftPosition('A7');
      $chart1->setBottomRightPosition('H20');
      
      //  Add the chart to the worksheet
      $objWorksheet->addChart($chart1);
      
      
      $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
      $objWriter->setIncludeCharts(TRUE);
      $objWriter->save(str_replace('.php', '.xlsx', __FILE__));
      

      正确生成,无任何错误

      可能是注释掉
      $dataseriesLabels2
      条目导致了问题。谢谢您的建议。但事实并非如此,我删除了注释,但仍然存在相同的问题。另外:
      PHPExcel\u Chart\u DataSeriesValues::\u construct
      的默认值为空的
      array()
      。您基于的文件包含两个图表,这两个图表之间是否存在冲突?我刚刚创建了一个文件,它根据您的数据构建了一个图表。否,在发生错误时,它只包含一个图表(我同时添加了一个条形图,希望在末尾有两个图表,但当时只有一个图表)。您的示例没有出现错误吗?我明白了,问题是
      PHPExcel\u Chart\u DataSeries::GROUPING\u STANDARD
      选项。我必须改用
      NULL
      。谢谢!馅饼/甜甜圈根本没有分组数据的概念是的,很有道理。然后应该纠正这些示例(它们也不能正常工作)!哪些具体例子
      33chartcreate pie.php
      当然正确哦,是的,没错。我指的是这个例子。我的错。总而言之:非常感谢!:-)