【发布时间】:2020-03-08 00:57:22
【问题描述】:
我正在尝试在我的 .Net Core Web 应用程序中创建一个 chart.js 图表,其中包含来自数据库的数据。我正在使用 ajax 调用从数据库中提取数据的方法,但我不确定如何将数据分组以显示在图表中。
目前我有一个看起来像这样的数据库:
我希望在底部显示时间并计算有多少工作成功以及有多少工作异常。目前我的图表是硬编码的。
// Area Chart Example
var ctx = document.getElementById("canvas")
var lineChartData = {
labels: ['January', 'February', 'March', 'April', 'May', 'June', 'July'],
datasets: [{
label: 'Failed',
borderColor: "MediumSeaGreen",
backgroundColor: "MediumSeaGreen",
fill: false,
data: [
30000, 30162, 26263, 18394, 18287, 28682, 31274, 33259, 25849,
24159, 32651, 31984, 38451
],
yAxisID: 'y-axis-1',
}, {
label: 'Exceptioned',
borderColor: "Tomato",
backgroundColor: "Tomato",
fill: false,
data: [
20000, 30162, 26263, 33259, 18287, 28682, 25849, 18394, 25849,
24159, 32651, 31984, 38451
],
yAxisID: 'y-axis-2'
}]
};
window.myLine = Chart.Line(ctx, {
data: lineChartData,
options: {
responsive: true,
hoverMode: 'index',
stacked: false,
title: {
display: true,
text: 'Processes'
},
scales: {
yAxes: [{
type: 'linear',
display: true,
position: 'left',
id: 'y-axis-1',
}, {
type: 'linear',
display: true,
position: 'right',
id: 'y-axis-2',
// grid line settings
gridLines: {
drawOnChartArea: false, // only want the grid lines for one axis to show up
},
}],
}
}
});
【问题讨论】:
-
你尝试过什么?
-
@Tseng 我没有尝试过任何东西,因为我无法理解它。
标签: javascript c# sql asp.net-core chart.js