嘿伙计们,我正在尝试更改我的Chartjs Icon传奇风格,如我的截图所示,我不太确定是否可能?
<!-- https://codepen.io/IrvingLee/pen/boqrEQ -->
Run Code Online (Sandbox Code Playgroud)
ɢʀᴜ*_*ᴜɴᴛ 11
是! 有可能的.
第一
在设置usePointStyle属性true为传说的标签,在你的图表选项,如下所示:
options: {
legend: {
labels: {
usePointStyle: true
}
},
...
Run Code Online (Sandbox Code Playgroud)
第二
为每个数据集设置pointStyle属性(根据您的要求),如下所示:
datasets: [{
...
pointStyle: 'line'
}, {
...
pointStyle: 'rect'
}]
Run Code Online (Sandbox Code Playgroud)
ᴡᴏʀᴋɪɴɢᴡᴏʀᴋɪɴɢ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
});Run Code Online (Sandbox Code Playgroud)
body {
background: #1D1F20;
padding: 16px;
}
.chart-container {
position: relative;
margin: auto;
height: 80vh;
width: 80vw;
}Run Code Online (Sandbox Code Playgroud)
<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>Run Code Online (Sandbox Code Playgroud)