I'm trying to make a custom tooltip for this chart but it isn't working:
(defn approved-invoice-chart [drafted-amt invoiced-amt]
(let [percent (get-percentage invoiced-amt drafted-amt)]
[ApexChart {:options (clj->js
{:chart {:id "invoice-chart"
:toolbar download-option-only}
:plotOptions {:radialBar
{:hollow
{:size "60%"}
:dataLabels
{:value
{:offsetY 154}}}}
:title {:text "Approved Invoices"
:align "left"}
:tooltip {:custom (str "Actual revenue is " percent "% of estimated revenue.")}}
:labels [["Revenue Estimate Total"
""
"Actual Revenue Total"]] ; these are styled separately to the values we want to import
:subtitle {:text ["" ; total estimated revenue
(str "" drafted-amt)
"" ; total actual revenue
(str "" invoiced-amt)] ; replace with real values later
:align "center"
:margin 0
:offsetX 0
:offsetY 196
:floating true
:style {:fontWeight "bold"
:fontSize "14px"}}
:colors (colours :orange-dark)})
:series [percent]
:type "radialBar"
:width 500
:height 400}]))
Assistant
It looks like there's a misunderstanding in how the :tooltip custom function is implemented within your ApexChart configuration. The :custom function within :tooltip options expects a JavaScript function, not a string. Also, to properly work with ClojureScript, you would typically use clj->js to translate ClojureScript data structures into JavaScript objects, but the function needs to be properly formatted as JavaScript. In this case, you'll want to embed a JavaScript function as a string and then ensure it's correctly interpreted.
Let's adjust the :tooltip configuration to reflect this. Here's a revised version of your chart configuration, focusing specifically on the :tooltip customization:
The :tooltip {:custom ...} part has been changed to use js/goog.global.eval with a function as a string. This way, we're embedding a JavaScript function definition directly. This function is called by ApexCharts to customize the tooltip. It receives an object with a few properties (series, seriesIndex, dataPointIndex, w) and returns a string with HTML content. Here, it's dynamically including the series value (percent) in the tooltip text.
Ensure you have properly configured the rest of your chart settings according to your actual data structure and visualization requirements.
Note the use of js/goog.global.eval. This approach works but also be aware of the security implications of using eval if the content you're evaluating comes from an untrusted source. In your specific case, as you're defining the function directly and not evaluating arbitrary input, it shouldn't pose a security risk.
Remember to replace download-option-only and any other placeholders or pseudo-code with working code/configuration for your specific needs.