Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't get callback example working #23

Open
songproducer opened this issue Oct 22, 2024 · 5 comments
Open

Can't get callback example working #23

songproducer opened this issue Oct 22, 2024 · 5 comments

Comments

@songproducer
Copy link

songproducer commented Oct 22, 2024

I'm able to choose the callback from the admin, but on the webpage it doesn't display.

I'm using this with the Wagtail News Template so the only difference I think is that I'm calling the chart from within the blocks.StreamBlock class

utils/blocks.py

CHART_CONFIG_CALLBACKS = (
        ('barchart_labels', 'Bigger font and bold labels'),
    )
class StoryBlock(blocks.StreamBlock):
        chart = ChartBlock(callbacks=CHART_CONFIG_CALLBACKS)

static_src/javascript/main.js

window.barchart_labels = function() {
    return {
        plugins: {
            datalabels: {
                font: {
                    size: 18,
                    weight: 'bold',
                },
                color: '#ff0000'
            }
        }
    }
}
@saevarom
Copy link
Member

Hi @songproducer
When you have loaded the page containing this example, can you go to the console and call window.barchart_labels - is the function present in the global scope?

@songproducer
Copy link
Author

I think it's present.

function barchart_labels()
​
length: 0
​
name: ""
​
prototype: Object { … }
​
<prototype>: function ()

@saevarom
Copy link
Member

OK. And are you overriding the template for the block? If so, you should have the data-callbacks attribute like it's done in https://github.com/overcastsoftware/wagtailcharts/blob/main/wagtailcharts/templates/wagtailcharts/blocks/chart_block.html

Try to view the source on your rendered page and see if you actually have data-callbacks on your canvas element.

@songproducer
Copy link
Author

Yes, I have data-callbacks attribute in the template override. I rendered {{self.callbacks}} and it displays:
None

@songproducer
Copy link
Author

Sorry, I realised I hadn't selected the callback. Now it displays:
barchart_labels
and the chart doesn't render

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants