简体   繁体   English

如何为顶点图表栏列宽中的所有栏设置固定宽度

[英]How to make fixed width for all bars in apexcharts bar column width

Since we are using dynamic data, the data length should also be dynamic.由于我们使用的是动态数据,因此数据长度也应该是动态的。 For example, if data length is 24 column width should be 35px.例如,如果数据长度为 24,则列宽应为 35px。 if data is 2 length that time also column width should be 35px.如果数据是 2 长度,那么列宽也应该是 35px。

apexchart using columnWidth in percentage so i am not able to specify exact width for all bars in all condition if there is 1 Bar, 5 Bar, 30 Bars.顶点图表使用 columnWidth 百分比,因此如果有 1 个条形、5 个条形、30 个条形,我无法在所有条件下指定所有条形的确切宽度。 it is working as responsive behaviour but i want to make it fixed width for all Bars它作为响应行为工作,但我想让所有条的宽度固定

  1. 在此处输入图像描述
  2. 在此处输入图像描述

I want columnWidth to fixed with 1st image size when there is 1 data also.当还有 1 个数据时,我希望 columnWidth 固定为第一个图像大小。 see in 2nd graph columnWidth is showing bigger than previous.在第二张图中看到 columnWidth 显示比以前大。 so i want fixed for all bars in all case.所以我想在所有情况下都固定所有酒吧。

Using: import ApexCharts from "react-apexcharts";使用:从“react-apexcharts”导入 ApexCharts; "react-apexcharts": "^1.3.6", “反应顶点图表”:“^1.3.6”,

In ApexCharts, there is no option to give columnWidth in pixels.在 ApexCharts 中,没有以像素为单位提供columnWidth的选项。 You can maybe try to set percentage width based on the number of categories present.您可以尝试根据存在的类别数量设置百分比宽度。 It won't be 100% accurate but might just solve the purpose.它不会 100% 准确,但可能只是解决目的。

With the chart width (w), a series of data (n), and the desired column width in px (x), I can get the width in percentage with this function:使用图表宽度 (w)、一系列数据 (n) 和以 px (x) 为单位的所需列宽,我可以使用此 function 获得宽度百分比:

const getPercentWidth = (w, n, x) => {
  const percentWidth = Math.round((x / (w / n)) * 100)
  return `${percentWidth}%`
}

You can check this issue on their github repo for more options in future.您可以在他们的 github 存储库中查看此问题,以获取更多选项。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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