admin管理员组文章数量:1353191
I am making a website which is predominantly for data visualisation, data is selected by the user (who also selects a chart type) and returned with PHP and I'm using Chart.js on the client side to generate the graphs. I'm trying to use as modular an approach as possible for reusability so that I can make different types of graphs with different data with this code.
The problem I have is that whilst most charts, such as line and bubble charts, work just fine pie and doughnut charts do not, instead it just outputs a series of rectangular blocks with numbers.
I apologise using an image of the chart output, I simply don't know how else to show the chart output and I've tried to explain it above - the graph output on the webpage.
This is the code responsible for generating the graph:
function makeChart(ctx, response, selectedColumn) {
if (myChart) {
myChart.destroy();
}
const chartTypeValue = chartTypeSelect.value;
const labels = response.map(item => item['Hour']);
const data = response.map(item => {
const value = item[selectedColumn];
return isNaN(value) ? value : parseFloat(value);
});
myChart = new Chart(ctx, {
type: chartTypeValue,
data: {
labels: labels,
datasets: [{
label: `Data for ${selectedColumn}`,
data: data,
backgroundColor: [
'rgb(255, 99, 132)',
'rgb(255, 159, 64)',
'rgb(255, 205, 86)',
'rgb(75, 192, 192)',
'rgb(54, 162, 235)',
'rgb(153, 102, 255)',
'rgb(201, 203, 207)'
],
}]
}
}
);
return myChart;
}
So I'd like to know how I might go about addressing this.
Thanks for your time and help.
Update:
I have added a var_dump to show the data structure (truncated for obvious reasons but the structure is consistent):
array(26280) {
[0]=>
array(2) {
["Hour"]=>
string(1) "0"
["DogID"]=>
string(9) "CANINE001"
}
[1]=>
array(2) {
["Hour"]=>
string(1) "1"
["DogID"]=>
string(9) "CANINE001"
}
[2]=>
array(2) {
["Hour"]=>
string(1) "2"
["DogID"]=>
string(9) "CANINE001"
}
本文标签: javascriptIs there a solution to Chartjs improperly outputting piedoughnut chartsStack Overflow
版权声明:本文标题:javascript - Is there a solution to Chart.js improperly outputting piedoughnut charts? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1743912454a2560642.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论