2amigos / yii2-chartjs-widget

ChartJs Widget For Yii2
https://2amigos.us
Other
109 stars 67 forks source link

Callbacks #30

Closed SereiaMaster closed 6 years ago

SereiaMaster commented 6 years ago

I can't make callbacks for tooltips...

Any can help?


options: {            
        tooltips: {
            callbacks: {
                label: function(tooltipItems, data) {
                    return data.datasets[tooltipItems.datasetIndex].label +': ' + tooltipItems.yLabel + ' €';
                }
            }

        }
    }`
tonydspaniard commented 6 years ago

@SereiaMaster I need more information... How are you doing it currently? The above code is plugin options clientOptions but I need to see how are you trying to implement it

SereiaMaster commented 6 years ago

@tonydspaniard Thanks for reply!

Above is my code...

` 'clientOptions' => [ 'tooltips' => [ 'titleFontSize' => 16, 'bodyFontSize' => 16, 'callbacks' => [ 'label' => function($tooltipItems, $data){ return 'test'; } ] ], ],

` Tooltips not showing... in browser console message is

` Chart.js:8637 Uncaught TypeError: callbacks.label.call is not a function at http://localhost:8080/advanced/backend/web/assets/57466138/Chart.js:8637:50 at Object.helpers.each (http://localhost:8080/advanced/backend/web/assets/57466138/Chart.js:5052:15) at ChartElement.getBody (http://localhost:8080/advanced/backend/web/assets/57466138/Chart.js:8630:12) at ChartElement.update (http://localhost:8080/advanced/backend/web/assets/57466138/Chart.js:8736:21) at ChartElement.handleEvent (http://localhost:8080/advanced/backend/web/assets/57466138/Chart.js:9069:8) at Chart.eventHandler (http://localhost:8080/advanced/backend/web/assets/57466138/Chart.js:4490:34) at listener (http://localhost:8080/advanced/backend/web/assets/57466138/Chart.js:4424:21) at HTMLCanvasElement.proxies.(anonymous function) (http://localhost:8080/advanced/backend/web/assets/57466138/Chart.js:9923:5) (anonymous) @ Chart.js:8637 helpers.each @ Chart.js:5052 getBody @ Chart.js:8630 update @ Chart.js:8736 handleEvent @ Chart.js:9069 eventHandler @ Chart.js:4490 listener @ Chart.js:4424 proxies.(anonymous function) @ Chart.js:9923

`


Sorry for my bad english.

tonydspaniard commented 6 years ago
'label' => new JsExpression('function($tooltipItems, $data){
return 'test';
}'
SereiaMaster commented 6 years ago

Thank you!!

Work Perfect!