gpt4 book ai didi

javascript - chart.js 响应条形图标签大小

转载 作者:行者123 更新时间:2023-11-29 19:20:46 25 4
gpt4 key购买 nike

所以我有一个使用 chart.js 的条形图,并且启用了响应。它似乎适用于某些图表,但不适用于其他图表。例如,我的条形图标签似乎没有随窗口调整大小,但其他一切确实使整个图表在较小的窗口尺寸下看起来非常奇怪。我怎样才能重新调整标签的大小,以便它们一起缩放?有任何想法吗?谢谢!

我的 fiddle :http://fiddle.jshell.net/SteveSerrano/e3o9z2wg/

HTML:

<canvas id="canvas" width="940" height="540"></canvas>

JS:

var barChartData = {
labels: ["Adjust claims fairly", "Pays promptly", "Resolves issues quickly", "Communicates clearly, honestly to agents", "Underwriter knowledge/expirience", "Listens, responds to agents", "Consistant underwriting", "Easy, intuitive functionality-technology", "Stable underwriting market", "Flexible underwriting when warrented"],
datasets: [
{
label: "My First dataset",
//new option, barline will default to bar as that what is used to create the scale
type: "line",
fillColor: "rgba(225,225,225,0.01)",
strokeColor: "rgba(0,0,0,1)",
pointColor: "rgba(0,0,0,1)",
pointStrokeColor: "#000000",
pointHighlightFill: "#fff",
pointHighlightStroke: "rgba(0,0,0,1)",
data: [9.5, 9.4, 9.3, 9.2, 9.2, 9.1, 9, 9, 9, 9]
}, {
label: "My First dataset",
//new option, barline will default to bar as that what is used to create the scale
type: "bar",
fillColor: "rgba(225,50,50,0.8)",
strokeColor: "rgba(225,50,50,1)",
pointColor: "rgba(220,20,220,1)",
pointStrokeColor: "#fff",
pointHighlightFill: "#fff",
pointHighlightStroke: "rgba(220,220,220,1)",
data: [7.4, 7.6, 6.2, 6.3, 6.8, 5.8, 7.1, 6.1, 7.6, 5.2]
}]
};
Chart.defaults.global.responsive = true;
//canvases
var lineBar = document.getElementById("canvas").getContext("2d");

//charts
var myLineBarChart = new Chart(lineBar).Overlay(barChartData);

最佳答案

这个问题更多地与真正长的 x 轴标签有关,而不是与响应能力有关。也就是说,设置 maintainAspectRatio 将解决您的问题。

Chart.defaults.global.maintainAspectRatio = false;

请注意,您也可以针对每个图表执行此操作。


如果你也想保持纵横比,你可以像https://stackoverflow.com/a/31699438/360067一样扩展图表来 trim 标签。

关于javascript - chart.js 响应条形图标签大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33133028/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com