【问题标题】:How do I make the correct X axis for my two line scatter chart in phpspreadsheet如何在 phpspreadsheet 中为我的两线散点图制作正确的 X 轴
【发布时间】:2019-07-18 01:49:09
【问题描述】:

使用 PHPSpreadsheet 制作两线散点图。我输入了电子表格单元格中的 x 和 Y 值。 PHPSpreadsheet 生成带有丑陋 X 轴的图表。 Y 数据,即大约 17 摄氏度到大约 45 摄氏度。Y 轴是 0 到 50,以 5 度为增量,完美。但是,X 数据是 0 到 34 分钟,增量为 2 分钟。 X 轴为 0 到 35 分钟,增量为一分钟。我附上两者的照片。

这是X轴刻度和数据集:

    $xAxisTickValues = [
new
DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_NUMBER,      'Worksheet!$C$1:$C$18', null, 18),
new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_NUMBER,  'Worksheet!$F$1:$F$18', null, 18) 
];
dataSeriesValues = [ 
new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_NUMBER, 'Worksheet!$D$1:$D$18' ,null , 18),
new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_NUMBER,  'Worksheet!$G$1:$G$18' ,null , 18)
];

不涉及任何错误。预期或期望的结果是 X 轴从 0 到 40,以 5 度为增量。

好的图表x轴是通过右键单击坏图表选择xy散点图并单击确定来实现的。 Excel自动生成好轴?

有人请指导我使用 PHPSpreadsheet 获得正确的轴。

【问题讨论】:

    标签: php phpspreadsheet


    【解决方案1】:

    我几乎知道我的问题的答案。 x 和 y 轴都应该由以下代码控制:

        $xaxis = new Axis();
    $xaxis->setAxisOptionsProperties('low', 0, 'autoZero', null, 'in', 'out', 0, 40, 5, 0);
    
    $title = new Title('Calorimetric Calibration');
    $yAxisLabel = new Title(html_entity_decode('Temp (°C)',ENT_QUOTES,'UTF-8'));
    $xAxisLabel = new Title('Time (Min)');
    
       // Create the chart
     $chart = new Chart(
      'chart1', // name
      $title, // title
      $legend, // legend
      $plotArea, // plotArea
      true, // plotVisibleOnly
      0, // displayBlanksAs
      $xAxisLabel, // xAxisLabel
      $yAxisLabel,  // yAxisLabel
      $yaxis, 
      $xaxis,
      null, 
      null
    );
    

    我可以改变 y 轴的所有方面。但是我不能对 x 轴的最大值和最小值做任何事情。它们似乎受以下控制:

        $xAxisTickValues = [
    new
    DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_STRING, 'Worksheet!$C$1:$C$18', null, 18), 
    
    new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_STRING, 'Worksheet!$F$1:$F$18', null, 18)
    ];
    

    如果我删除刻度线控件,它们看起来 x 轴是由数据点的数量控制的。 所以,这就是我的答案中几乎出现的地方。如何让 setAxisOptionsProperties 接管并允许我根据需要设置最大值和最小值?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-03-11
      • 2016-11-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多