【发布时间】:2019-10-29 17:38:36
【问题描述】:
因此,我想保留“日期”数据类型,并使用 Angular 8 中的设置,在该设置中,我正在设置多个数据集,其中包含一系列标记为“笛卡尔”的类型。我从这里获取文档:https://www.chartjs.org/docs/latest/axes/cartesian/time.html#time-cartesian-axis。但是,如果您可以将“悬停标签”设置为不同,我要么阅读不正确,要么丢失。如果我不及时保持它会爆炸,但我可以在我的代码中使用回调设置 X 轴,如下所示:
const dashInput = this.getDashboardInput();
const daysDifference = (+dashInput.endDate.getTime() - +dashInput.startDate.getTime()) / 1000 / 60 / 60 / 24;
if (daysDifference >= 150 ) {
this.enrollmentsAndCompletionsChartInUI.options.scales.xAxes[0].time.unit = 'month';
this.enrollmentsAndCompletionsChartInUI.options.scales.xAxes[0].time.displayFormats.month = 'MM/YY';
} else if (daysDifference >= 60) {
this.enrollmentsAndCompletionsChartInUI.options.scales.xAxes[0].time.unit = 'week';
this.enrollmentsAndCompletionsChartInUI.options.scales.xAxes[0].time.displayFormats.week = 'MM/DD/YY';
} else {
this.enrollmentsAndCompletionsChartInUI.options.scales.xAxes[0].time.unit = 'day';
this.enrollmentsAndCompletionsChartInUI.options.scales.xAxes[0].time.displayFormats.day = 'MM/DD/YY';
}
但我没有看到您如何设置此悬停框属性。任何帮助将不胜感激,因为我可能只是错过了文档中的一些简单内容。
目前 ChartJs scales 的配置设置是这样设置的。但是该组件会覆盖如上所示的设置。
scales: {
xAxes: [{
id: 'time axis',
type: 'time',
time: {
unit: 'day',
displayFormats: {
day: 'MM/DD/YY'
}
}
}],
yAxes: [{
scaleLabel: {
display: true,
labelString: 'Enrollments'
},
ticks: {
beginAtZero: true,
min: 0
}
}]
}
明确地说,我希望悬停在 XAxis 的格式上,例如 08/05/19
【问题讨论】:
-
请分享用于 x 和 y 轴的 chartjs 比例配置
标签: javascript angular typescript chart.js