简体   繁体   中英

Align caption vertically APEXCHARTS

I built this chart using Apex charts

图表

But both the 'Chart' title and the caption are not aligned, the title should be aligned relative to the graph, and the vertically aligned caption.

the title aligned so by placing the property align: 'center'

but my main problem is in the legend, I went behind the documentation and found this command verticalAlign: 'middle' to be used inside the ´legend:´ property.

Does anyone know how to make this work properly?

You will need to add a legend key inside your chart object, and fill it with an object contains the ´verticalAlign: 'middle'´ property. So you will end up adding this:

 legend: {verticalAlign: 'middle'}

Below is an example:

var options = {
  chart: {
    type: 'line'
  },
  legend: {
  verticalAlign: 'middle'
  },
  series: [{
    name: 'sales',
    data: [30,40,35,50,49,60,70,91,125]
  }],
  xaxis: {
    categories: [1991,1992,1993,1994,1995,1996,1997, 1998,1999]
  }
}

There is no property called verticalAlign for the legend.

You can vertically align the legend to center with CSS

.apexcharts-legend {
  justify-content: center;
}

The solution for vertically aligning the legend would be:

.apexcharts-legend {
  justify-content: center !important;
  top: 0 !important;
}

because you have to force overwrite the default which is justify-conent: flex-start

edit: you also need top: 0 !important to really get it centered but that might mess up your other charts

I guess for you this answer is one year too late but maybe it's helpful for someone else.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM