apexcharts.js icon indicating copy to clipboard operation
apexcharts.js copied to clipboard

Stacked bar chart - border radius applied to last element of series only

Open blueeDeveloper opened this issue 4 years ago • 8 comments

Description

Suppose i have a series as shown below. If "NOT TESTED" data is 0, then border radius should be applied to the previous series element. i.e. SKIP. That is not the case happening in my codepen.

series: [ { name: 'SUCCESS', data: result.success }, { name: 'FAILURE', data: result.failure }, { name: 'SKIP', data: result.skip }, { name: 'NOT TESTED', data: result.untested } ],

Expected Behavior

Stacked bar chart should have border radius to top most element in all scenarios. Even if last element of chart series is empty, border radius should be applied to the next last element.

Screenshots

  1. As you can see, the border radius is absent when the last element of the series is 0. Screen Shot 2021-09-25 at 8 49 00 PM

  2. When i apply below css, border radius gets applied to every series. I wanted it to get applied only the topmost.

.apexcharts-bar-series.apexcharts-plot-series .apexcharts-series path { clip-path: inset(0% 0% -11% 0% round 16px); }

Screen Shot 2021-09-25 at 8 49 27 PM

Reproduction Link

CODEPEN LINK BELOW https://codepen.io/a166617/pen/NWgOQNe

blueeDeveloper avatar Sep 26 '21 03:09 blueeDeveloper

I have the same problem by vue-apexchart

Tim260399 avatar Sep 28 '21 14:09 Tim260399

I have the same problem by vue-apexchart

Hi @Tim260399 - have you raised a similar bug issue elsewhere ?

blueeDeveloper avatar Sep 29 '21 02:09 blueeDeveloper

As a workaround you can try using the new borderRadius feature that applies a border to all series by defining it as an array.

borderRadius: [5]

However, in this case do not use a very large border radius or it can impact the chart accuracy

brianlagunas avatar Sep 29 '21 14:09 brianlagunas

@brianlagunas thanks for suggesting the workaround. It somehow hides the border radius of the charts at the middle but the overall percentage bar shows reduced too and that will be very confusing for the end user. :(

for ex below. All 3 bars sums up to 80 but due to borderRadius: [5], the first 2 bars donot show that the total is 80.

Screen Shot 2021-09-29 at 9 18 46 AM

blueeDeveloper avatar Sep 29 '21 16:09 blueeDeveloper

don't forget to remove the

.apexcharts-bar-series.apexcharts-plot-series  .apexcharts-series path {
  clip-path: inset(0% 0% -11% 0% round 16px);
}

I get this: image

But yes, this will slightly impact the accuracy of the chart

brianlagunas avatar Sep 29 '21 16:09 brianlagunas

@brianlagunas - True, its similar to not having border radius. Can you please let us know if a fix will be available anytime soon ?

blueeDeveloper avatar Sep 29 '21 16:09 blueeDeveloper

Still an issue for 3.33.2

alexprey avatar Mar 05 '22 00:03 alexprey

Having the same problem here. Still an issue for 3.35.3.

danicaus avatar Jul 04 '22 22:07 danicaus

And still in 3.36.0

gyurielf avatar Nov 08 '22 11:11 gyurielf

There is a new property

plotOptions: {
  bar: {
    borderRadiusApplication: "around", // "around" / "end" 
    borderRadiusWhenStacked: "last" // "all"/"last"
  }
}

Docs: https://apexcharts.com/docs/options/plotoptions/bar/#borderRadiusApplication

junedchhipa avatar Nov 08 '22 12:11 junedchhipa

There is a new property

plotOptions: {
  bar: {
    borderRadiusApplication: "around", // "around" / "end" 
    borderRadiusWhenStacked: "last" // "all"/"last"
  }
}

Docs: https://apexcharts.com/docs/options/plotoptions/bar/#borderRadiusApplication

Yep, thy! I found it, a little while ago.

But, i think the part of the question is: on the first attached img, the second and 3rd colums should be rounded as well. Because those are last (shown) items.

gyurielf avatar Nov 08 '22 13:11 gyurielf

@gyurielf I have tried below plotOptions for stacked bar chart but didn't solve the problem. I don't see border radius applied. can you please let me know if it works for you ?

plotOptions: { bar: { borderRadiusApplication: "around", borderRadiusWhenStacked: "last" } }

Screenshot 2022-11-08 at 9 36 50 AM

satishreddykoppella avatar Nov 08 '22 17:11 satishreddykoppella

@satishreddykoppella

https://codepen.io/gyurielf/pen/VwdPLQM

gyurielf avatar Nov 08 '22 20:11 gyurielf

@gyurielf I have edited details of codepen and attaching screenshot here Note:- I have edited the Product D data

  • Product D can have zero for some index. In that case how can i apply border radius last product ( can be any Product Not necessarily Product D) in each bar graph.
Screenshot 2022-11-08 at 10 52 31 PM

satishreddykoppella avatar Nov 09 '22 06:11 satishreddykoppella

@satishreddykoppella

That is the problem, we can't.

gyurielf avatar Nov 09 '22 07:11 gyurielf

You can use next code

    plotOptions: {
        bar: {
          horizontal: false,
          borderRadius: 10,
          borderRadiusApplication: "end",
          borderRadiusWhenStacked: "last",

          dataLabels: {
            total: {
              enabled: true,
              style: {
                fontSize: "13px",
                fontWeight: 900,
              },
            },
          },
        },
      },

image

developOleg250 avatar Feb 01 '23 10:02 developOleg250

You can use next code

    plotOptions: {
        bar: {
          horizontal: false,
          borderRadius: 10,
          borderRadiusApplication: "end",
          borderRadiusWhenStacked: "last",

          dataLabels: {
            total: {
              enabled: true,
              style: {
                fontSize: "13px",
                fontWeight: 900,
              },
            },
          },
        },
      },

image

@developOleg250 I have tried didn't work for me. Can you please share some implemented codepen link ?

satishreddykoppella avatar Feb 01 '23 23:02 satishreddykoppella

I also get the same issue here, is there any solution for this?

wentaoGather avatar Mar 17 '23 20:03 wentaoGather

I got help from a friendly soul and this worked for me:

plotOptions:
    bar:
      horizontal: false
      borderRadius:
        - 5
        - 5
      borderRadiusApplication: end
      borderRadiusWhenStacked: all

Lunkobelix avatar Mar 21 '23 11:03 Lunkobelix

@Lunkobelix I have implemented the changes you suggested. But I could see some style issue. can you please share some implemented codepen link ? Screenshot 2023-03-28 at 12 35 57 PM

satishreddykoppella avatar Mar 28 '23 19:03 satishreddykoppella

I hope this example can help you.

https://pastebin.com/ZVeBfJku

Lunkobelix avatar Apr 03 '23 08:04 Lunkobelix

Same problem here. If last data set have a zero value, no border radius is applied. No working solution yet :(

@junedchhipa can you help with this?

mizinin avatar Jul 11 '23 12:07 mizinin

Same problem.

guillaume-caulier avatar Oct 18 '23 12:10 guillaume-caulier

Why is this closed? We ran into the same issue.

If you use borderRadiusWhenStacked: "last" as proposed it looks weird, if any 'top' data value is 0. This is what we're trying to avoid.

Reproducible sample with the proposed solution (that didn't work for us) is at: https://codepen.io/JGwinner/pen/GRzPXEG

With:

         bar: {
            horizontal: false,
            endingShape: "rounded",
            borderRadius: 20,
            borderRadiusApplication: "end", // "around" / "end" 
            borderRadiusWhenStacked: "last" // "all"/"last"          
           },

image

jgwinner avatar Dec 05 '23 22:12 jgwinner

I'd propose to reopen this issue with regards to latest comments. I'm facing the same issue and borderRadiusWhenStacked: "last" does not solve an issue if top data points contain 0 value.

yevhenii-f avatar Dec 28 '23 10:12 yevhenii-f

still an issue

dima-kov avatar Feb 07 '24 20:02 dima-kov

I used @brianlagunas css property to create a solution. This is how I did it, it works great, you might need to tweak it a bit to fit your needs:

first get the series of your chart: const seriesElements = document.querySelectorAll('#yourChartId .apexcharts-bar-series.apexcharts-plot-series .apexcharts-series')

then determine the length of series data, based on your first serie, running this: const seriesDataLength = seriesElements[0].querySelectorAll('.apexcharts-bar-area').length

finally iterate over all of them and set the border to the last one:

for (let i = 0; i < seriesDataLength; i++) {
  const lastElements = []

  seriesElements.forEach((serie) => {
    const bar = serie.querySelectorAll('.apexcharts-bar-area')[i]
    if (bar && bar.getAttribute('barHeight') !== '0') {
      lastElements.push(bar)
    }
  })

  const lastElement = lastElements[lastElements.length - 1]

  if (lastElement) {
    lastElement.setAttribute('clip-path', 'inset(0% 0% -100% 0% round 4px)')
  }
}

fernandolangaro avatar Mar 01 '24 13:03 fernandolangaro

Capture can any body help me with this?

mwinner313 avatar Mar 25 '24 09:03 mwinner313