PHPExcel - Y轴与数据图表重叠 [英] PHPExcel - Y-Axis overlaps data chartarea
问题描述
我在PHPExcel中的y轴标签定位有问题。
I am having a problem with the y-axis label positioning in PHPExcel.
创建图表时,y轴标签不会出现在绘图区域的左侧,它们始终与绘图区域重叠,从类别4开始为0.
When I create a chart, the y-axis labels are not appearing to the left of the plot area, they are always overlapping the plot area, starting at category 4 instead of 0.
我假设问题是由我的类别x轴值导致的,Excel无法确定y轴相对于y轴的位置数据。我的类别(x轴)值为字符串形式:
I am assuming the issue is being caused by my category-x-axis values and Excel not being able to determine where to place the y-axis relative to the data. My category (x-axis) values are in string form:
yyyy, i.e. 1980 1981 1982 1983 etc.
这里是我的PHPExcel图表创建代码,除了y轴定位。
$ b
And here is my PHPExcel chart creation code, all working except for the y-axis positioning.
$labels = array(
new PHPExcel_Chart_DataSeriesValues('String', "'Report Summary'!C1", null, 1),
new PHPExcel_Chart_DataSeriesValues('String', "'Report Summary'!D1", null, 1)
);
$chrtCols = "'Report Summary'!B2:B$rowNum";
$chrtVals = "'Report Summary'!C2:C$rowNum";
$chrtVals2 = "'Report Summary'!D2:D$rowNum";
$periods = new PHPExcel_Chart_DataSeriesValues('Number', $chrtCols, null, $rowNum-1);
$values = new PHPExcel_Chart_DataSeriesValues('Number', $chrtVals, null, $rowNum-1);
$values2 = new PHPExcel_Chart_DataSeriesValues('Number', $chrtVals2, null, $rowNum-1);
$series = new PHPExcel_Chart_DataSeries(
PHPExcel_Chart_DataSeries::TYPE_AREACHART, // plotType
PHPExcel_Chart_DataSeries::GROUPING_STANDARD, // plotGrouping
array(0,1), // plotOrder
$labels, // plotLabel
array($periods,$periods), // plotCategory
array($values,$values2) // plotValues
);
$series->setPlotDirection(PHPExcel_Chart_DataSeries::DIRECTION_COL);
$layout = new PHPExcel_Chart_Layout();
$plotarea = new PHPExcel_Chart_PlotArea($layout, array($series));
$chart = new PHPExcel_Chart('sample', null, null, $plotarea);
$chart->setTopLeftPosition('A1', 24, 24);
$chart->setBottomRightPosition('B18', -24);
$actSheet->addChart($chart);
有一个设置告诉y轴在类别0处穿越x轴,它自动选择错误的十字路口?还是有一种方法,我可以改变源数据,使其自动选择正确的交集?
Is there a setting to tell the y-axis to cross the x-axis at category 0 rather than it automatically selecting the wrong intersection? Or is there a way I can alter the source data to make it automatically select the correct intersection?
编辑:一个可能的解决方法可能是简单地将y轴线颜色设置为无线,并且y轴标签显示到低而不是nextTo,但是,我不认为PHPExcel有能力改变轴线颜色设置在这一点。或者是吗?
A 'possible' workaround may be to simply set the y-axis Line Color to "no Line", and the y-axis label display to "low" rather than "nextTo", however, I do not think PHPExcel has the ability to alter axis Line Color settings at this point. Or does it?
推荐答案
PHPExcel / Classes / Writer / Excel2007 / Chart .php
There is a bug at least in my version of PHPExcel in PHPExcel/Classes/Writer/Excel2007/Chart.php
查找:
if ($id1 > 0) {
$objWriter->startElement('c:crossAx');
$objWriter->writeAttribute('val', $id2);
$objWriter->endElement();
并将$ id2更改为$ id1:
and change the $id2 to $id1:
if ($id1 > 0) {
$objWriter->startElement('c:crossAx');
$objWriter->writeAttribute('val', $id1);
$objWriter->endElement();
轴应该是正确的。
这篇关于PHPExcel - Y轴与数据图表重叠的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!