chartjs / chartjs-chart-financial

Chart.js module for charting financial securities
MIT License
725 stars 197 forks source link

How could I change the tooltip display for the "candlestick"+"line" chart? #32

Closed rashearth closed 6 years ago

rashearth commented 6 years ago

Hi I have a trouble with candlestick + line chart mixed chart. the tooltips does not show properly for the line chart.(the line chart tooltip shows undefined) The code is listed below. Could you tell me how I could solve this?

default

`

Home

Candlestick

`

rashearth commented 6 years ago

I fixed the issue by changing the chart.financial.js as follow

tooltips: {
        callbacks: {

            label: function(tooltipItem, data) {
                var o = data.datasets[tooltipItem.datasetIndex].data[tooltipItem.index].o;
                var h = data.datasets[tooltipItem.datasetIndex].data[tooltipItem.index].h;
                var l = data.datasets[tooltipItem.datasetIndex].data[tooltipItem.index].l;
                var c = data.datasets[tooltipItem.datasetIndex].data[tooltipItem.index].c;

var point= data.datasets[tooltipItem.datasetIndex].data[tooltipItem.index].y;

                var fractionalDigitsCount = data.datasets[tooltipItem.datasetIndex].fractionalDigitsCount;
                if (fractionalDigitsCount !== undefined) {
                    fractionalDigitsCount = Math.max(0, Math.min(100, fractionalDigitsCount));
                    o = o.toFixed(fractionalDigitsCount);
                    h = h.toFixed(fractionalDigitsCount);
                    l = l.toFixed(fractionalDigitsCount);
                    c = c.toFixed(fractionalDigitsCount);

                }

if (typeof o!== "undefined") {

        return ' O: ' + o + '    H: ' + h + '    L: ' + l + '    C: ' + c;

}

if (typeof o=== "undefined") {

        return point;

}

} } } };