3

I'm using apexcharts with vue. I want the sparkline graph to take 100% of the width of it's parent.

So this is what I did:

<div>
  <apexchart
    :options="chartOptions"
    :series="series"
    height="150"
    style="width: 100%"
  />
</div>

I tried also to set the width as a prop of the component but it behaves the same.

Here are my chart options:

chartOptions: {
   chart: {
       type: 'area',
       sparkline: {
           enabled: true
       }
   },
   dataLabels: {
       enabled: false
   },
   stroke: {
       curve: 'straight',
       width: 3,
   },
   xaxis: {
       type: 'datetime',
   }
}

So nothing special here, it is copied from apex dashboard example, the only thing I've added is trying to set the width 100%.

It overflows it's parent (green) and the parent's container (yellow) as shown here:

enter image description here

But also when I resize the window(without refresh) it doesn't retain its size, it becomes smaller than the parent:
enter image description here

How can I make it fill the width of it's parent (green container) and keep it that way (responsive)?

Thanks

dor272
  • 550
  • 1
  • 6
  • 26
  • Are you using CSS flex around the charts? – junedchhipa Sep 29 '20 at 19:44
  • in a way. I'm using vuetify's grid. but its 3-4 level above the chart. – dor272 Sep 29 '20 at 20:37
  • I figured out that the gap after resizing is due to missing data in the series and the fact that I have set a max attribute for the x axis. now after resize it takes 100% like it should but on first render it overflows. I found this issue https://stackoverflow.com/questions/55326858/apex-charts-dont-resize-properly-when-using-flexbox but in my case there are no errors of failing to get the parent node. – dor272 Sep 30 '20 at 07:22

5 Answers5

12

I had the same issue, I just removed display: flex on the container and that resolved the issue :)

Abed abuSalah
  • 156
  • 2
  • 5
2

I figured out that the gap after resizing is due to missing data in the series and the fact that I have set a max attribute for the x axis.

So that solved issue #2.

Apparently the charts render before it should, so it doesn't get the right parent's width, a workaround that solved it for me was to not render the chart after the component is mounted.

dor272
  • 550
  • 1
  • 6
  • 26
  • 1
    Hi, can you show how to solved the problem? I'm using vuetify v-flex for the apexchart but facing the same problem. – luvwinnie Jan 10 '22 at 07:18
0

you can do xaxis: { tickPlacement: "between", }, by defalut it is "On",

it just places you data in between so you can see a little space on left & right end of the x axis.

0

If you're using flex on your container and you can't stop using it try using max-width: 100% !important; in this container - works for me.

ivall
  • 27
  • 7
-1
chart: {
    width: '100%'
}

this might fix your issue

my issue resolved using this method ref

atiquratik
  • 1,296
  • 3
  • 27
  • 34