highcharts-react icon indicating copy to clipboard operation
highcharts-react copied to clipboard

Broken stacking column chart if margin is defined

Open artemkasan opened this issue 6 years ago • 4 comments

Hallo,

I faced to a problem that if I define margin for stacking column chart, it draw columns one under another.

Here is reproduction code:

import React, { useState } from "react";
import { render } from "react-dom";
import Highcharts from "highcharts";
import HighchartsReact from "highcharts-react-official";

const options = {
  chart: {
    type: "column",
    margin: [5, 0, 25, 30]
  },
  xAxis: {
    categories: ["Apples", "Oranges", "Pears", "Grapes", "Bananas"]
  },
  yAxis: {},
  plotOptions: {
    column: {
      stacking: "normal"
    }
  },
  series: [
    {
      name: "One",
      data: [5, 3, 4, 7, 2]
    },
    {
      name: "Two",
      data: [2, 2, 3, 2, 1]
    }
  ]
};

const App = () => {
  const [stateOptons, setStateOptons] = useState(options);

  const handleClick = () => {
    const newOptions = JSON.parse(JSON.stringify(stateOptons));
    newOptions.series[0].data[0]++;
    setStateOptons(newOptions);
  };

  return (
    <div>
      <button onClick={handleClick}>Click</button>
      <HighchartsReact highcharts={Highcharts} options={stateOptons} />
    </div>
  );
};

render(<App />, document.getElementById("root"));

At first it render chart correctly. But when user clicks on "Click" button, columns started to draw one under another.

But if I remove margin from chart everything start to work fine.

artemkasan avatar Nov 04 '20 14:11 artemkasan

Finally, I've found how to reproduce this bug in "highcharts" will redirect bug there

artemkasan avatar Nov 04 '20 14:11 artemkasan

@artemkasan,

Thank you for contacting us.

I reproduced your code and I can not see the difference between the version with defined margin and without. Could you point me out the difference? Demo: https://stackblitz.com/edit/react-c2zsgq?file=index.js

Basts avatar Nov 05 '20 11:11 Basts

I've reported a bug to the highcharts team: https://github.com/highcharts/highcharts/issues/14488 The bug was introduced in the version 8.1.1 of the highcharts. So, I've updated the version of the highcharts to 8.2.2 and it started to reproduce. On button click all bars go down.

artemkasan avatar Nov 05 '20 11:11 artemkasan

Hi @artemkasan,

This problem is fixed in the latest master and will be available in the next version. If you need to use v8.2.2, use some of the workarounds from this issue: https://github.com/highcharts/highcharts/issues/14453

Best regards!

ppotaczek avatar Nov 09 '20 16:11 ppotaczek