• Resolved jnaran

    (@jnaran)


    Hi there,

    Thanks for an amazing plugin!

    I’m not sure if this is the default setting, but whenever I hover over my stacked column chart, the values for the datasets appear in the tooltip, but not the names of the datasets. How do I enable the dataset names so that it correctly displays in the tooltip?

    For example, this is what i currently displaying in the tooltip when I hover over a column:

    29 Jan
    27
    15
    13
    5

    This is what I’d like to display instead:

    29 Jan
    Reg Adults: 27
    Reg Kids: 15
    Visitors: 13
    Newcomers: 5

    Thanks, Jayesh

Viewing 9 replies - 1 through 9 (of 9 total)
  • Thread Starter jnaran

    (@jnaran)

    Just to follow up on this, I can fix the tooltip labels in the browser console using the code below:

    m_chart_chartjs_3889_1.chart_args.options.plugins.tooltip.callbacks.label = function(context) {
                            var label = context.dataset.label || '';
                            if (label) {
                                label += ': ';
                            }
                            if (context.parsed.y !== null) {
                                label += context.parsed.y;
                            }
                            return label;
                        }

    But how do I modify “m_chart_chartjs_3889_1” before it has been created? For more context, I can add a sum at the bottom of the tooltip using the chart defaults:

    Chart.defaults.plugins.tooltip.callbacks.afterBody = (ttItem) => (Sum: ${ttItem.reduce((acc, val) => (acc + val.raw), 0)});

    But when I try to modify the default label function, it reverts to a different function after the chart loads. This is what I want it to be:

    Chart.defaults.plugins.tooltip.callbacks.label = function(context) {
                            var label = context.dataset.label || '';
                            if (label) {
                                label += ': ';
                            }
                            if (context.parsed.y !== null) {
                                label += context.parsed.y;
                            }
                            return label;
                        }

    This is what it loads as when I access it via the console:

    >m_chart_chartjs_3889_1.chart_args.options.plugins.tooltip.callbacks.label
    < a=>m_chart_chartjs_helpers.chart_tooltip_label(a,r,t,e,_)

    I think it is getting overwritten at some point. Any help would be greatly appreciated!

    Plugin Author methnen

    (@methnen)

    I think this is a bug on my end. Probably a result of the other fix. I need to make sure I’m testing for multiple situations I think.

    I’ll take a look at this soon. Because yes, the plugin itself plugs into the char tooltip callback so I suspect my callback is overwriting your callback.

    Plugin Author methnen

    (@methnen)

    Jayesh,

    Sorry for the delay on this. Life has been something else the last month.

    I’m sitting down to work on this and I’m realizing that I might need to se your data set and your settings for the chart in question in order to properly duplicate the issue.

    Would you be willing to pass that all my way?

    jamie AT methnen.com

    Is my email address.

    Also please post here when you send it so I know to look for your email.

    Thread Starter jnaran

    (@jnaran)

    Thanks Jamie, really appreciate your help. Just sent you an email.

    Plugin Author methnen

    (@methnen)

    Did you see my email reply with a possible fix?

    • This reply was modified 6 months, 1 week ago by methnen.
    Thread Starter jnaran

    (@jnaran)

    No I didn’t see it for some reason – there was nothing in my spam either. Not sure what happened there. Did you get my email with all my data?

    Plugin Author methnen

    (@methnen)

    Thought that might be the case. I just sent it again, hopefully it gets to you this time. Let me know please either way.

    Plugin Author methnen

    (@methnen)

    OK, your server is refusing it, even with it zipped, probably because it’s got some JS code in it. I’ll put that somewhere else and then try again. ??

    Plugin Author methnen

    (@methnen)

    This issue was resolved over email and the fix will be in the next release of M Chart.

Viewing 9 replies - 1 through 9 (of 9 total)
  • You must be logged in to reply to this topic.