I'm using the chart.js 2.6.0 library.
I'm trying to made a comparation line chart like the Google Analytics compare functionality: Screenshot
I have to compare two revenue date periods of an ecommerce.
I would like to draw two x Axes with different labels, one x Axe for the first period, one for the second.
Now I can draw two lines, one for each period, and two xAxes, but I can use only one array of labels, giving me the following result: screeshot
Obviously wrongly, every period-two point on the line, is corresponding to the period 1 label (see the hover infowindow in the second screeshot)
This is my code
var ctx = $("#ordersCompareChart");
var chart = new Chart(ctx, {
type: 'line',
data: {
labels: data.labels,
datasets: [{
borderColor: "#E25F5F",
label: 'Period 1: From ' + $('#from_first').val() + ' to ' + $('#to_first').val(),
data: data.values_first,
borderWidth: 3,
xAxisID: "x-axis-1",
},
{
borderColor: "#2793DB",
label: 'Period 2: From ' + $('#from_second').val() + ' to ' + $('#to_second').val(),
data: data.values_second,
borderWidth: 3,
xAxisID: "x-axis-2",
},
]
},
options: {
scales: {
xAxes: [
{
display: true,
tipe: "time",
scaleLabel: {
display: true,
labelString: 'Period 1'
},
id: "x-axis-1"
},
{
display: true,
tipe: "time",
id: "x-axis-2",
labels: data.labels_second,
scaleLabel: {
display: true,
labelString: 'Period 2'
},
id: "x-axis-2"
}
],
yAxes: [{
display: true,
scaleLabel: {
display: true,
labelString: 'Total'
},
ticks: {
callback: function(value, index, values) {
return value.toLocaleString("de-DE",{style:"currency", currency:"EUR"});
}
}
}]
}
}
});
Thanks to whoever can answer