apexcharts / apexcharts.js

📊 Interactive JavaScript Charts built on SVG
https://apexcharts.com
MIT License
14.37k stars 1.3k forks source link

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

Closed blueeDeveloper closed 1 year ago

blueeDeveloper commented 3 years ago

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

Tim260399 commented 3 years ago

I have the same problem by vue-apexchart

blueeDeveloper commented 3 years ago

I have the same problem by vue-apexchart

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

brianlagunas commented 3 years ago

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

blueeDeveloper commented 3 years ago

@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
brianlagunas commented 3 years ago

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

blueeDeveloper commented 3 years ago

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

alexprey commented 2 years ago

Still an issue for 3.33.2

danicaus commented 2 years ago

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

gyurielf commented 1 year ago

And still in 3.36.0

junedchhipa commented 1 year ago

There is a new property

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

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

gyurielf commented 1 year ago

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.

satishreddykoppella commented 1 year ago

@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
gyurielf commented 1 year ago

@satishreddykoppella

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

satishreddykoppella commented 1 year ago

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

Screenshot 2022-11-08 at 10 52 31 PM
gyurielf commented 1 year ago

@satishreddykoppella

That is the problem, we can't.

developOleg250 commented 1 year ago

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

satishreddykoppella commented 1 year ago

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 ?

wentaoGather commented 1 year ago

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

Lunkobelix commented 1 year ago

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

plotOptions:
    bar:
      horizontal: false
      borderRadius:
        - 5
        - 5
      borderRadiusApplication: end
      borderRadiusWhenStacked: all
satishreddykoppella commented 1 year ago

@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
Lunkobelix commented 1 year ago

I hope this example can help you.

https://pastebin.com/ZVeBfJku

mizinin commented 1 year ago

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?

guillaume-caulier commented 1 year ago

Same problem.

jgwinner commented 11 months ago

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

yevhenii-f commented 10 months ago

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.

dima-kov commented 8 months ago

still an issue

fernandolangaro commented 8 months ago

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)')
  }
}
mwinner313 commented 7 months ago

Capture can any body help me with this?

PedroMTSilva commented 5 months ago

Still an issue. I'm working with ng-apexcharts 1.7.7 and Angular13. Also, the options for 'borderRadiusApplication' and 'borderRadiusWhenStacked' just don't work at all.

FrenchMajesty commented 3 months ago

@junedchhipa As of July 2024, still an issue. See attached screenshot:

Screenshot 2024-07-29 at 3 43 56 PM
ibrahimelement commented 2 months ago

This is still an issue, why has this not been fixed?

brunofuentes commented 1 month ago

hi. having the same issue. Is it expected to be fixed anytime soon? thanks.