FVANCOP / ChartNew.js

MIT License
420 stars 143 forks source link

Mixed chart with "stacked bars" and "lines", calculatedScale is undefined on two axis #470

Closed serve1337 closed 7 years ago

serve1337 commented 7 years ago

I have created a chart with "stacked bars", "lines" and two y-axis. chart_example

My goal: the "stacked bars" should be relative to the left axis and the "lines" should be relative to the right axis. My problem: if i setting it up (code on the bottom) i get an error "calculatedScale is undefined". If I set both chart types (stacked bars and lines) relative to the left axis it is working like shown in the image above.

Is it possible to get an fix or snippet how to get it work like i expected?

My dataset:

var mydata1 = {
    labels: ['...'],
    datasets: [{
fillColor : '#0041c4',
title : 'Bar1',
data : ['...'],
axis : 1,
strokeColor : '#0041c4',
pointColor : '#0041c4',
pointStrokeColor : '#0041c4'
}, {
fillColor : '#96ff38',
title : 'Bar2',
data : ['...'],
axis : 1,
strokeColor : '#96ff38',
pointColor : '#96ff38',
pointStrokeColor : '#96ff38'
}, {
type : 'Line',
fillColor : '#ff820d',
title : 'Line1',
data : ['...'],
axis : 2,
strokeColor : '#ff820d',
pointColor : '#ff820d',
pointStrokeColor : '#ff820d'
}]
}

My options:

var newopts = {
    yAxisRight : true ,
    yAxisUnit : '',
    yAxisLabel : 'kW',
    yAxisUnit2 : '',
    yAxisLabel2 : 'kWh',
    yAxisMinimumInterval: 1,
    yAxisMinimumInterval2: 1,
    graphMin : 0,
    graphMin2 : 0,
    forceSecondScale : true,
    responsive : false,
    showYAxisMin: true
}

My javascript call in the html: var myLine = new Chart(document.getElementById("myChart").getContext("2d")).StackedBar(mydata1, newopts);

Best, serve

FVANCOP commented 7 years ago

Thanks for reporting this problem; Problem is that, at the beginning, lines were not allowed over stacked bar charts and, when there are no lines, a second axis has no sence. In the code that you provide, of course, it makes a sence. A fix will be delivered in next version (soon available).

FVANCOP commented 7 years ago

Download the last published version. With this version, you can define double-axis for stacked bar chart. see https://github.com/FVANCOP/ChartNew.js/wiki/100_035_DoubleAxis.

serve1337 commented 7 years ago

Thank you very much, it's working perfect.