![](/img/trans.png)
[英]React resizable only resizing the width of the box, not the height
[英]Resizable/Expendable box annotation in ChartJs
我使用chartjs-插件的注释中chartJs与ReactJs。 但是在框注释中有一种方法如何调整框的大小,以便我可以使用注释的最小值、最大值。
我的选项代码:`
options: {
scales: {
y: {
beginAtZero: true
}
},
plugins: {
autocolors: false,
annotation: {
annotations: {
box1: {
type: "box",
xMin: 1,
xMax: 2,
yMin: 5,
yMax: 10,
backgroundColor: "rgba(255, 99, 132, 0.25)"
}
}
}
}
}
`
这是我的代码沙箱ReactJs-ChartJs
是的,您可以深入了解图表对象的选项部分,调整注释的配置,然后调用chart.update()
这将更新注释。
例子:
const options = { type: 'line', data: { labels: ["Red", "Blue", "Yellow", "Green", "Purple", "Orange"], datasets: [{ label: '# of Votes', data: [12, 19, 3, 5, 2, 3], borderWidth: 1 }] }, options: { plugins: { annotation: { annotations: { box1: { type: "box", xMin: 1, xMax: 2, yMin: 5, yMax: 10, backgroundColor: "rgba(255, 99, 132, 0.25)" } } } } } } const ctx = document.getElementById('chartJSContainer').getContext('2d'); const chart = new Chart(ctx, options); document.getElementById("tt").addEventListener("click", () => { chart.options.plugins.annotation.annotations.box1.yMax = 16; chart.update(); }); document.getElementById("rr").addEventListener("click", () => { chart.options.plugins.annotation.annotations.box1.yMax = 8; chart.update(); });
<body> <canvas id="chartJSContainer" width="600" height="400"></canvas> <button id="tt">Update annotation to 16</button> <button id="rr">Update annotation to 8</button> <script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/3.4.0/chart.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/chartjs-plugin-annotation/1.0.2/chartjs-plugin-annotation.js"></script> </body>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.