gpt4 book ai didi

chart.js - 更改 Chartjs 图例图标样式

转载 作者:行者123 更新时间:2023-12-04 16:58:01 26 4
gpt4 key购买 nike

我正在尝试更改我的 Chartjs 图标图例样式,如我的屏幕截图所示。是否可以 ?
enter image description here

<!-- https://codepen.io/IrvingLee/pen/boqrEQ --> 

最佳答案

是的! 有可能的。

第一

设置 usePointStyle 属性(property)到 true 对于图例标签,在您的图表选项中,如下所示:

options: {
legend: {
labels: {
usePointStyle: true
}
},
...

第二

套装 pointStyle 每个数据集的属性(根据您的要求),例如:
datasets: [{
...
pointStyle: 'line'
}, {
...
pointStyle: 'rect'
}]

ᴡᴏʀᴋɪɴɢ ᴇxᴀᴍᴘʟᴇ ⧩

var data = {
labels: ['Value [mm]', ''],
datasets: [{
label: "Hi-Hi Limit",
type: 'line',
data: [5432, 5432],
backgroundColor: 'rgba(250, 255, 255, 0)',
borderColor: 'rgba(255, 4, 0, 100)',
borderWidth: 3,
radius: 0,
pointStyle: 'line'
}, {
label: "Hi Limit",
type: 'line',
data: [5130, 5130],
backgroundColor: 'rgba(250, 255, 255, 0)',
borderColor: 'rgba(250, 255, 0, 100)',
borderWidth: 3,
radius: 0,
pointStyle: 'line'
}, {
label: "Lo Limit",
type: 'line',
data: [905, 905],
backgroundColor: 'rgba(250, 255, 255, 0)',
borderColor: 'rgba(250, 255, 0, 100)',
borderWidth: 3,
radius: 0,
pointStyle: 'line'
}, {
label: "Lo-Lo Limit",
type: 'line',
data: [604, 604],
backgroundColor: 'rgba(250, 255, 255, 0)',
borderColor: 'rgba(255, 4, 0, 100)',
borderWidth: 3,
radius: 0,
pointStyle: 'line'
}, {
type: 'line',
label: "Level",
data: [4800, 4800],
backgroundColor: 'rgba(0, 119, 220, 1)',
borderColor: 'rgba(0, 119, 220, 1)',
borderWidth: 1,
radius: 0,
pointStyle: 'rect'
}],

};

var options = {
legend: {
position: 'right',
labels: {
usePointStyle: true
}
},
scales: {
yAxes: [{
gridLines: {
display: true,
color: "rgba(255,99,132,0.2)"
}
}],
xAxes: [{
gridLines: {
display: false
}
}]
}
};

Chart.Bar('chart', {
options: options,
data: data
});
body {
background: #1D1F20;
padding: 16px;
}

.chart-container {
position: relative;
margin: auto;
height: 80vh;
width: 80vw;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.5.0/Chart.min.js"></script>
<div class="chart-container">
<canvas id="chart"></canvas>
</div>

关于chart.js - 更改 Chartjs 图例图标样式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46439315/

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