Giter Site home page Giter Site logo

Comments (6)

coderpauloo avatar coderpauloo commented on August 20, 2024 1

Thanks a lot for your help and explanations, I managed to make it work the way I needed to :)

Have a nice day !

from ux.

smnandre avatar smnandre commented on August 20, 2024

I don't think you can write JS code in PHP.

You probably should use a custom stimulus controller and define the callback on initialization

--> https://symfony.com/bundles/ux-chartjs/current/index.html#extend-the-default-behavior

from ux.

coderpauloo avatar coderpauloo commented on August 20, 2024

ok thanks, I'll try this way but it still feels weird the php configuration does not cover this part of the features

from ux.

coderpauloo avatar coderpauloo commented on August 20, 2024

I tried your solution by creating this custom controller :

`
//piechart_controller.js
import { Controller } from '@hotwired/stimulus';

export default class extends Controller {
connect() {
this.element.addEventListener('chartjs:pre-connect', this._onPreConnect);
}

disconnect() {
    this.element.removeEventListener('chartjs:pre-connect', this._onPreConnect);
}

_onPreConnect(event) {
    const chart = event.detail.chart;
    console.log('here');
    chart.config.options.plugins.tooltip.callbacks.label = function(context) {
      return 'test';
    };

    chart.update();
}

}
`

twig :

{{ render_chart(expensesDistributionChart, {'data-controller': 'piechart'}) }}

But I can't manage to make this work, I don't even see my console.log, would you have any example of detailed documentation about how to set this up please ?

from ux.

smnandre avatar smnandre commented on August 20, 2024

You must update the config and not the chart, as it's not yet created in the preConnect event

https://symfony.com/bundles/ux-chartjs/current/index.html#extend-the-default-behavior

   _onPreConnect(event) {
        // The chart is not yet created
        // You can access the config that will be passed to "new Chart()"
        console.log(event.detail.config);
        
        // ...

This should work better

from ux.

smnandre avatar smnandre commented on August 20, 2024

I'm glad if i can help :)

Happy coding!

from ux.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.