react-chartjs icon indicating copy to clipboard operation
react-chartjs copied to clipboard

legendTemplate and tooltipTemplate not working?

Open palmerj3 opened this issue 10 years ago • 6 comments

I've tried utilizing the legendTemplate chart option and the tooltipTemplate chart option but neither seem to be working for me.

I've even tried modifying the example code to utilize non-existent variables and I see no errors in the console so it appears these options are being ignored?

I've tried this for a line chart and a bar chart.

palmerj3 avatar Jan 15 '16 19:01 palmerj3

This issue helps with getting a legend to show.

pjho avatar Jan 18 '16 17:01 pjho

Trying that example now returns:

Uncaught Invariant Violation: Can only set one ofchildrenorprops.dangerouslySetInnerHTML.

Is there any other way to get the legend to show?

RamonBeast avatar Feb 19 '16 10:02 RamonBeast

dangerouslySetInnerHTML is the only way to achieve this?

dougmolineux avatar Mar 18 '16 19:03 dougmolineux

Just wanted to add this, I was able to modify the Tooltip by using this:

chartOptions = {
      multiTooltipTemplate: "<%if (datasetLabel){%><%=datasetLabel%>: <%}%><%= value %>",
    }

dougmolineux avatar Mar 18 '16 19:03 dougmolineux

I'm running into the same issues; At first, I was looking at the ChartJS v2 docs which really through me off. The old values can be found in the old ChartJS docs here

I wasn't able to get a legend to render without dangerouslySetInnerHTML, but the fix shown here does work, though it feels like I'm strapping on duct-tape to show a legend.

Regarding tooltips, I was able to change the format of the text with the multiTooltipTemplate option. According to the old docs, you can also define 'customTooltips' in options, it takes a function that returns a tooltip; it gives me some useful data about the point but it's missing legendColors (which I'm assuming is because I'm rendering the legend manually). ~~The v1.1 demo shows them using jQuery to pull down the element, so I'm guessing the lack of a ref is why it can't get the colors from the legend and instead returns white squares.~~

edit: Turns out the colors missing in the object were from not having a pointColor, once I set one they were populated. I got rid of the custom function and at least I've got the right colors on my tooltips now.

blairmorris avatar Jul 13 '16 21:07 blairmorris

@blairmorris can you share example?

maxfarseer avatar Sep 24 '16 06:09 maxfarseer