我使用chart.js创建了一张柱状图,并启用了响应式。看起来有些图表效果不错,但有些则不太好。例如,我的柱状图标签似乎无法随着窗口大小变化而缩放,而其他所有内容都可以,在较小的窗口尺寸下,整个图表看起来非常奇怪。我该如何调整标签大小以使其一起缩放?有什么想法吗?谢谢!
我的示例代码:http://fiddle.jshell.net/SteveSerrano/e3o9z2wg/ Html:
我的示例代码: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);
responsive
选项将调整图表大小以适应其父容器。尝试在父容器上设置最大高度。 - potatopeelings