charts - 如何更改 ChartJS 线段中的 pointBackgroundColor?
问题描述
我正在尝试更改图形线段部分中的 pointBackGround 颜色,但它似乎仅适用于borderColor。这是我的代码。有谁知道如何改变它们?顺便说一句,我正在使用 chart.js 版本 3.1.1。
const data = {
datasets: [
{
type: 'line',
label: `${props.stationSelected.selected.label2}`,
borderColor: '#feb1c3',
backgroundColor: '#feb1c3',
pointRadius: 3,
pointBackgroundColor: '#feb1c3',
fill: false,
data: hourlyData,
tension: 0.5,
segment: {
borderColor: ctx => findEstimate(ctx, '#7c7c7c'), // this works
pointBackgroundColor: ctx => findEstimate(ctx, '#7c7c7c'), // this does not work
}
},
],
}
const findEstimate = (ctx, value) => {
const dt = ctx.p0.$context.raw.gageHeightDateTime
const start = modalDataRaw.gageHeightDateTimeStart
const stop = modalDataRaw.gageHeightDateTimeEnd
if (dt >= start && dt <= stop) {
return value
}
}
解决方案
我已经这样解决了。只需根据您的任务更改上下文条件即可。
const test = (ctx, value) => (ctx.p1DataIndex >= showLast ? value : undefined)
const point = (ctx, trainCol, testCol) => ctx.index >= showLast ? testCol : trainCol
const data = {
labels: trainDates.map(val => val.format("DD-MM")),
datasets: [
{
label: "Test plot",
data: values,
borderColor: "rgb(75, 192, 192)",
fill: false,
pointStyle: "circle",
pointBackgroundColor: ctx => point(ctx, "rgb(75, 192, 192)", "rgb(192,75,75)"),
pointBorderColor: ctx => point(ctx, "rgb(75, 192, 192)", "rgb(192,75,75)"),
segment: {
borderColor: ctx => test(ctx, "rgb(192,75,75)"),
},
},
],}
推荐阅读
- wordpress - 用鼠标滚轮放大在我的网站上不起作用
- safari - 视频未在 Safari 中显示
- javascript - 如何删除输入字段的轮廓
- sql-server - 如何在插入 MSSQL Server 之前执行查询
- flutter - 创建按钮时出现“BOTTOM OVERFLOWING BY 1.1 PIXELS”错误
- azure - 在 Azure Blob 存储中覆盖后如何命名 csv 文件
- r - 如何使用ggplot2绘制分成多个类别的数据?
- google-sheets - 查询同一工作表内的多个选项卡的问题
- javascript - 根据键过滤 Json 数据并将值分配给反应中的状态
- python-3.x - Python Selenium:对于 [List] 中的 x:send_keys(x) 丢失字符