我有一个折线图,显示值与月份的关系。我想从mysql提取这些值并将其以正确的顺序放置, 我的数据库看起来像:
month | cpi | team
jan 1.0 A
jan 1.1 B
feb 1.2 A
feb 1.3 B...so on
到目前为止,我已经连接到数据库,并且,我已经尝试了几种方法,但是总是以相同的观点结束,那么如何从mysql中获取此信息?在我的上一次尝试中,只有您看到的时候,我才将一月字段标记为标签。这是图表代码的示例:
*<div class="container"></div>
<script>
function createConfig(gridlines, title) {
return {
type: 'line',
data: {
labels: ['January', 'February', 'March', 'April', 'May', 'June', 'July','August','September','October','November','December'],
datasets: [{
label: 'Density',
backgroundColor: window.chartColors.orange,
borderColor: window.chartColors.orange,
data: [<?PHP echo $CPI; ?>, 0.00, 1.05, 4.00, 1.15, 1.24, 2.00],
fill: false,
},*
};
}
window.onload = function() {
var container = document.querySelector('.container');
[ {
title: 'CPI Charts',
gridLines: {
display: true,
drawBorder: true,
drawOnChartArea: true,
drawTicks: false,
}
}].forEach(function(details) {
var div = document.createElement('div');
div.classList.add('chart-container');
var canvas = document.createElement('canvas');
div.appendChild(canvas);
container.appendChild(div);
var ctx = canvas.getContext('2d');
var config = createConfig(details.gridLines, details.title);
new Chart(ctx, config);
});
};
谢谢!