在水平条形图中设置最大条形高度

问题描述 投票:0回答:1

有可能吗?

我尝试过类似的东西

        "elements": {
            "bar": {
                "maxHeight": 10,
                "height": 10
            }
        },

但是它不起作用...

当我有很多值时,看起来像这样:

enter image description here

并且当只有几个值时,它看起来像这样(我希望它像上图中一样薄):enter image description here

height
1个回答
0
投票

我自己回答了一个问题。

首先,我在div中创建图表:

    <div id="chart-control">
        <canvas id="chart"></canvas>
    </div>

然后我根据行数[data.length] *(4/3)更改div的高度

    document.getElementById("chart-control").style.height = (data.length * (4/3)) + "em";
© www.soinside.com 2019 - 2024. All rights reserved.