I am having trouble locating a time scale on the Y axis of my graph.
The objective of this graph is to compare, between different machine operators, the time (minutes and seconds) that were necessary to manufacture the same piece.
When wanting to graph only an empty graph is observed, showing me only the names of the operators on the X axis.
Using a sql query that I do in my controller I get this information:
{
"pieces": [
{
"id": 2,
"name": "Miguel",
"time": "00:02:00",
"denomination": "Eje 340 d19",
"quantity": 60,
"rol": 2
},
{
"id": 4,
"name": "Luis",
"time": "00:04:00",
"denomination": "Eje 340 d19",
"quantity": 30,
"rol": 2
}
]
}
As you can see in the query for the same part manufactured by different operators, there is a different machining time, just that is what I want to dump on my graph and I do not know how to spend the minutes ("time": "00:02:00","time": "00:04:00",
) on the Y axis
In this getChartDataPiece () function I use ajax to receive my array pieces. I am also stating time as an array and just there my machining times are stored, this is how I run it:
function getChartDataPiece(name) {
$.ajax({
url: '/admin/dashboard/getChartPiece/' + name,
type: 'GET',
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
},
dataType: 'json',
success: function (response) {
console.log(response);
var time = [];
var operator = [];
for (var i in response.pieces) {
time.push(response.pieces[i].time);
operator.push(response.pieces[i].name);
}
renderChartPiece(operator, time);
},
error: function (response) {
console.log(response.time);
console.log(response.operator);
}
});
}
I'm not sure if those machining times (minutes and seconds) are recognizable by chart.js
This is how I'm trying to graph with function renderChartPiece(operator, time):
function renderChartPiece(operator, time) {
var ctx1 = document.getElementById("times").getContext('2d');
var myChart1 = new Chart(ctx1, {
type: 'bar',
data: {
labels: operator,
datasets: [{
label: 'Partida',
data: time,
borderColor: 'rgba(75, 192, 192, 1)',
backgroundColor: 'rgba(75, 192, 192, 1)',
borderWidth: 1,
yAxisID: 'Tiempos',
xAxisID: 'Operarios',
}],
},
options: {
scales: {
yAxes: [{
id: "Tiempos",
ticks: {
beginAtZero: true
},
scaleLabel: {
display: true,
labelString: 'Tiempos'
}
}],
xAxes: [{
id: "Operarios",
scaleLabel: {
display: true,
labelString: 'Operarios'
}
}],
},
title: {
display: true,
text: "Ordenes de trabajo"
},
legend: {
display: true,
position: 'bottom',
labels: {
fontColor: "#17202A",
}
},
}
});
}
Please I NEED your help