douni9620 2019-07-18 01:49
浏览 287

如何在phpspreadsheet中为我的双线散点图制作正确的X轴

Using PHPSpreadsheet to make a two line scatter chart. I put in the x and Y values from the spreadsheet cells. PHPSpreadsheet generates the chart with a ugly X-axis. Y data ie about 17 degrees C to about 45 degrees C. The Y axis is 0 to 50in 5 degree increments, perfect. But, the X data is 0 to 34 minutes in 2 minute increments. The X axis is 0 to 35 minutes in one minute increments. I am attaching a picture of both.

The bad axis

Good X axis

This is the X axis ticks and the data set:

    $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)
];

No errors are involved. The expected or desired results would be an X axis of 0 to 40 in 5 degree increments.

The good chart x axis was achieved by right clicking the bad chart selecting xy scatter chart and clicking OK. Excel made the good axis automatically?

Would someone please guide me to get the proper axis using PHPSpreadsheet.

  • 写回答

1条回答 默认 最新

  • dtdfj08626 2019-07-22 02:42
    关注

    I do know the answer to my question, almost. Both x and y axis are supposed to be controlled by the following code:

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

    I can vary all aspects of the y axis. But I can not do anything with the x axis max and min. It appears they are controlled by the following:

        $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)
    ];
    

    If I remove the tick marks control, it them appears the x axis is controlled by the number of data points. So, that is where the almost comes in my answer. How can I get the setAxisOptionsProperties to take over and allow me the set the max and mins as I want to?

    评论

报告相同问题?

悬赏问题

  • ¥20 测距传感器数据手册i2c
  • ¥15 RPA正常跑,cmd输入cookies跑不出来
  • ¥15 求帮我调试一下freefem代码
  • ¥15 matlab代码解决,怎么运行
  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法