Столкнулся с такой проблемой. Есть 2 графика на Chart js, 1 из них линейный с ним всё в порядке, 2-й столбчатый у обоих графиков ось X типом time. Стобчатый график stacked:true. Проблема в том что если у столбчатого графика стоит тип оси время то всплывающие подсказки на нём не отображаются. Если стоит любой другой тип то всё хорошо. В чём может быть проблема и какие пути решения.
function graph_sea(data){
preg_data = JSON.parse(data);
date_search = [];
platzcard = [];
common = [];
siting = [];
compartment = [];
suite = [];
SV = [];
var platzcard_seats = [];
var common_seats =[];
var siting_seats =[];
var compartment_seats = [];
var suite_seats =[];
var SV_seats = [];
i = 0
$.each( preg_data, function( key, value ) {
if (key == ""){
return;
}
date_search[i] = key /* moment(key).format("D/MM") */;
delete preg_data[key]['plane_price'];
if (preg_data[key][i]){
$.each( preg_data[key], function(num_arr, val) {
switch (val['code_type_car']){
case '1':
platzcard.unshift(val['count_seqts']);
break;
case '2':
common.unshift(val['count_seqts']);
break;
case '3':
siting.unshift(val['count_seqts']);
break;
case '4':
compartment.unshift(val['count_seqts']);
break;
case '5':
suite.unshift(val['count_seqts']);
break;
case '6':
SV.unshift(val['count_seqts']);
break;
}
});
} else {
i++; return;
};
platzcard_seats[i] = summ_seats(platzcard);
common_seats[i] = summ_seats(common);
siting_seats[i] = summ_seats(siting);
compartment_seats[i] = summ_seats(compartment);
suite_seats[i] = summ_seats(suite);
SV_seats[i] = summ_seats(SV);
/* platzcard_seats.unshift(summ_seats(platzcard));
common_seats.unshift(summ_seats(common));
common_seats.unshift(summ_seats(siting));
compartment_seats.unshift(summ_seats(compartment));
suite_seats.unshift(summ_seats(suite));
SV_seats.unshift(summ_seats(SV)); */
platzcard = [];
common = [];
siting = [];
compartment = [];
suite = [];
SV = [];
i++;
});
var ctx = document.getElementById("Graphs_seats").getContext('2d');
var Graphs_seats = new Chart(ctx, {
type: 'bar',
//labels: date_search,
data: {
labels: '',
datasets: [
{
label: 'Плацкарт',
data: '',
yAxisID: "y-seats",
borderColor:'rgb(58, 56, 56)',
backgroundColor: 'rgb(58, 56, 56)',
fill: false,
},
{
label: 'Общий',
data: '',
yAxisID: "y-seats",
borderColor: 'rgb(98, 107, 69)',
backgroundColor: 'rgb(98, 107, 69)',
fill: false,
},
{
label: 'Сидячий',
data: '',
yAxisID: "y-seats",
borderColor: 'rgb(214, 61, 54)',
backgroundColor: 'rgb(214, 61, 54)',
fill: false,
},
{
label: 'Купе',
data: '',
yAxisID: "y-seats",
borderColor: 'rgb(243, 115, 44)',
backgroundColor: 'rgb(243, 115, 44)',
fill: false,
},
{
label: 'Люкс',
data: '',
yAxisID: "y-seats",
borderColor: 'rgb(115, 193, 93)',
backgroundColor: 'rgb(115, 193, 93)',
fill: false,
},
{
label: 'СВ',
data: '',
yAxisID: "y-seats",
borderColor: 'rgb(0, 51, 86)',
backgroundColor: 'rgb(0, 51, 86)',
fill: false,
}
]
},
options: {
responsive: true,
borderSkipped: "left",
showAllTooltips: true,
title: {
display: true,
text: title_graphs('seats'),
fontSize: 20,
fontColor: '#003356',
},
legend: {
display: true,
position: 'bottom',
labels: {
boxWidth: 10,
boxHeight: 10,
boxBackground: 'lime',
fontColor: 'black'
},
},
plugins: {
datalabels: {
color: 'white',
align: 'center',
anchor: 'center',
display: function(context) {
if (context.dataset._meta[context.chart.id].hidden !== true){
return context.dataset.data[context.dataIndex] > (context.chart.scales['y-seats'].max*0.05);
} else {
return false;
}
},
font: {
size: 11,
weight: 'bold'
},
formatter: function(value, context) {
if(value>1000){
return (value/1000).toFixed(1)+'k'
}else{
Math.round(value)
}
}
}
},
scales: {
yAxes: [{
type: "linear",
display: true,
stacked: true,
id: "y-seats",
position: "left",
scaleLabel: {
display: true,
labelString: "Места",
fontSize: "20",
fontColor: "#00507C"
},
ticks: {
callback : function (value) { return value + ' М.'; },
},
}],
xAxes: [{
offset: true,
stacked: true,
type: 'time',
time: {
unit: 'day',
unitStepSize: 1,
displayFormats: {
'day': 'D/MM'
},
},
scaleLabel: {
display: true,
fontSize: "20",
fontColor: "#00507C"
},
gridLines: {
display : false,
}
}]
},
tooltips: {
mode: 'index',
axis: 'xy',
callbacks: {
// Use the footer callback to display the sum of the items showing in the tooltip
title:function(tooltipItem) {
/* date_preg = tooltipItem[0].xLabel.split('/');
date = date_preg[0]+ "."+date_preg[1]+"."+moment().format("YYYY");
return date; */
return moment(tooltipItem[0].xLabel).format("DD.MM.YYYY");
},
label: function(tooltipItem, data) {
return data.datasets[tooltipItem.datasetIndex].label + ': '+ tooltipItem.yLabel+' Мест';
},
footer: function(tooltipItems, data) {
var sum = 0;
tooltipItems.forEach(function(tooltipItem) {
sum += data.datasets[tooltipItem.datasetIndex].data[tooltipItem.index];
});
return 'Всего: ' + sum;
},
}
},
/* // Container for pan options
pan: {
// Boolean to enable panning
enabled: false,
// Panning directions. Remove the appropriate direction to disable
// Eg. 'y' would only allow panning in the y direction
mode: 'xy',
rangeMin: {
// Format of min zoom range depends on scale type
//x: 500,
y: 1
},
rangeMax: {
// Format of max zoom range depends on scale type
//x: 100000,
y: 10000
}
},
// Container for zoom options
zoom: {
// Boolean to enable zooming
enabled: false,
// drag: true,
// Zooming directions. Remove the appropriate direction to disable
// Eg. 'y' would only allow zooming in the y direction
mode: 'xy',
rangeMin: {
// Format of min zoom range depends on scale type
x: 10,
y: 10
},
rangeMax: {
// Format of max zoom range depends on scale type
x: 10000,
y: 10000
}
} */
}
});
Graphs_seats.data.datasets[0].data = Object.values(platzcard_seats);
Graphs_seats.data.datasets[1].data = Object.values(common_seats);
Graphs_seats.data.datasets[2].data = Object.values(siting_seats);
Graphs_seats.data.datasets[3].data = Object.values(compartment_seats);
Graphs_seats.data.datasets[4].data = Object.values(suite_seats);
Graphs_seats.data.datasets[5].data = Object.values(SV_seats);
//console.log(date_search.reverse());
Graphs_seats.data.labels = date_search;
Graphs_seats.update();
$( document ).ready(function() {
$("#btn").click(
function(){
Graphs_seats.destroy();
return false;
}
);
});
}
Апостиль в Лос-Анджелесе без лишних нервов и бумажной волокиты
Основные этапы разработки сайта для стоматологической клиники
Продвижение своими сайтами как стратегия роста и независимости