It looks like there's a misunderstanding in how the :tooltip option is being set, particularly with the usage of :custom within it. The :custom function in ApexCharts needs to be a JavaScript function that returns a string, which represents the custom HTML content of the tooltip. Since you're working with ClojureScript, you'll need to properly convert a ClojureScript function to a JavaScript function that ApexCharts can utilize.
Let's correct this by defining a proper JavaScript function for the :custom tooltip. You'll need to use js* or #js to interop with JavaScript, depending on your need.
Here’s how you could adjust your tooltip customization:
-
Using :custom Properly: The function passed to :custom should accept parameters that ApexCharts provides (like series, seriesIndex, dataPointIndex, w). These parameters allow you to tailor the tooltip's content based on the data point being hovered.
-
Interop with JavaScript: You'll need to define a JavaScript function that returns the desired string. This can be done using clj->js in combination with #js or directly defining the function using js*.
Given these points, let's try to adjust your tooltip definition. Note, this example uses #js to directly interject JavaScript code:
(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 (fn [series seriesIndex dataPointIndex w]
(str "Actual revenue is "
(.toFixed (aget series seriesIndex) 2)
"% of estimated revenue."))
;; Note: Above is a simplistic implementation.
;; You might need to adjust based on actual data structure.
}
:labels [["Revenue Estimate Total"
""
"Actual Revenue Total"]]
:subtitle {:text [""
(str "$" drafted-amt)
""
(str "$" invoiced-amt)]
: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}]))
Key changes and points to note:
- Function for
:tooltip: The :custom field now correctly uses a JavaScript function (interop via fn). This function gets relevant data (series, indices) and uses them to create a tooltip string. Be mindful of what series, seriesIndex, and dataPointIndex contain, as your actual data structure may require different handling.
- String Building: It uses ClojureScript's
str for string manipulation. Ensure that the indices you're using to access your data (aget in the example) align with how your data is structured.
- Precision:
.toFixed(2) is used for formatting the percentage with two decimal places. You might need to adjust this based on your needs or data format.
Remember, the specifics of accessing data within the :custom function might need tweaking based on how your series data is structured.