Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't create contour chart (surface 2d) #2931

Closed
lvlukola opened this issue Jul 11, 2022 · 2 comments · Fixed by #2933
Closed

Can't create contour chart (surface 2d) #2931

lvlukola opened this issue Jul 11, 2022 · 2 comments · Fixed by #2933
Labels

Comments

@lvlukola
Copy link

I'm trying to plot contour chart (surface 2d), but I'm getting surface 3d chart

The library can do it?

$dataSeriesLabels = [[
        new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_STRING, null, null, 1, ['5-6']),
        new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_STRING, null, null, 1, ['6-7']),
        new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_STRING, null, null, 1, ['7-8']),
    ];

    $xAxisTickValues = [
        new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_NUMBER, null, null, 9, [1, 2, 3, 4, 5, 6, 7, 8, 9]),
    ];

    $dataSeriesValues = [
        new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_NUMBER, null, null, 9, [6, 6, 6, 6, 6, 6, 5.9, 6, 6]),
        new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_NUMBER, null, null, 9, [6, 6, 6, 6.5, 7, 7, 7, 7, 7]),
        new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_NUMBER, null, null, 9, [6, 6, 6, 7, 8, 8, 8, 8, 7.9]),
    ];

    $series = new DataSeries(
        DataSeries::TYPE_SURFACECHART,
        DataSeries::GROUPING_STANDARD,
        range(0, count($dataSeriesValues) - 1),
        $dataSeriesLabels,
        $xAxisTickValues,
        $dataSeriesValues,
        null, // plotDirection
        null, // smooth line
        DataSeries::STYLE_LINEMARKER  // plotStyle
    );

    $plotArea = new PlotArea(null, [$series]);
    $legend = new ChartLegend(ChartLegend::POSITION_BOTTOM, null, false);

    $title = new Title('График распредления температур в пределах кр');

    $chart = new Chart(
        'chart2',
        $title,
        $legend,
        $plotArea,
        true,
        DataSeries::EMPTY_AS_GAP,
    );

    $chart->setTopLeftPosition("A$1");
    $chart->setBottomRightPosition("P$20");

    $sheet->addChart($chart);
@oleibman
Copy link
Collaborator

You should set your grouping to null rather than DataSeries::GROUPING_STANDARD. Without that change, I was unable even to open the output file successfully. PhpSpreadsheet should probably be changed to not generate the grouping tag for surface charts.

That does not fix your problem. Apparently Excel requires that its view3D tag be populated even for non-3D surface charts. For now, you can accomplish that with the following code:

    $chart
        ->setRotX(90)
        ->setRotY(0)
        ->setRAngAx(0)
        ->setPerspective(0);

While I am looking into the problem from the first paragraph, I will also see if there's a way for PhpSpreadsheet to handle this automatically without the application having to add that statement.

@lvlukola
Copy link
Author

Thanks. It's OK!

oleibman added a commit to oleibman/PhpSpreadsheet that referenced this issue Jul 12, 2022
Fix PHPOffice#2931. If surface charts are written with c:grouping tag, Excel will treat them as corrupt. Also, some 3D-ish Xml tags are required when 2D surface charts are written, else they will be treated as 3D. Also eliminate a duplicate line identified by PHPOffice#2932.
@oleibman oleibman mentioned this issue Jul 12, 2022
7 tasks
oleibman added a commit that referenced this issue Jul 17, 2022
Fix #2931. If surface charts are written with c:grouping tag, Excel will treat them as corrupt. Also, some 3D-ish Xml tags are required when 2D surface charts are written, else they will be treated as 3D. Also eliminate a duplicate line identified by #2932.
MarkBaker added a commit that referenced this issue Jul 18, 2022
### Added

- Add Chart Axis Option textRotation [Issue #2705](#2705) [PR #2940](#2940)

### Changed

- Nothing

### Deprecated

- Nothing

### Removed

- Nothing

### Fixed

- Fix Encoding issue with Html reader (PHP 8.2 deprecation for mb_convert_encoding) [Issue #2942](#2942) [PR #2943](#2943)
- Additional Chart fixes
  - Pie chart with part separated unwantedly [Issue #2506](#2506) [PR #2928](#2928)
  - Chart styling is lost on simple load / save process [Issue #1797](#1797) [Issue #2077](#2077) [PR #2930](#2930)
  - Can't create contour chart (surface 2d) [Issue #2931](#2931) [PR #2933](#2933)
- VLOOKUP Breaks When Array Contains Null Cells [Issue #2934](#2934) [PR #2939](#2939)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

Successfully merging a pull request may close this issue.

2 participants