我有一个折线图,它显示了数值和月份。我想从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);
});
};
谢谢您!
暂无答案!
目前还没有任何答案,快来回答吧!