+
{# Heading levels will need to be configurable depending on page surroundings #}
{{ params.title }}
{{ params.subtitle }}
-
+
{% if params.caption %}
{{ params.caption }}
{% endif %}
-
- {% set config_scriptid = ["config--", params.uuid] | join %}
- {{ params.config|json_script(config_scriptid) }}
-
- {% if params.annotations_values %}
- {% set annotations_values_scriptid = ["annotations-values--", params.uuid] | join %}
- {{ params.annotations_values|json_script(annotations_values_scriptid) }}
- {% endif %}
-
{% if params.download_title and (params.download_image or params.download_csv or params.download_excel) %}
{% if params.download_title %}
{{ params.download_title }}
{% endif %}
@@ -33,5 +31,17 @@
{% endif %}
{% endif %}
+
+ {# script tags to pass json data to the javascript component #}
+
+ {% if params.annotations_values %}
+
+ {% endif %}
{% endmacro %}
diff --git a/cms/static_src/javascript/components/highcharts-base-chart.js b/cms/static_src/javascript/components/highcharts-base-chart.js
index 407ac25f..18767579 100644
--- a/cms/static_src/javascript/components/highcharts-base-chart.js
+++ b/cms/static_src/javascript/components/highcharts-base-chart.js
@@ -16,13 +16,16 @@ class HighchartsBaseChart {
this.title = this.node.dataset.highchartsTitle;
this.useStackedLayout = this.node.hasAttribute('data-highcharts-use-stacked-layout');
const chartNode = this.node.querySelector('[data-highcharts-chart]');
- const chartId = chartNode.dataset.highchartsId;
// We start with some config in the correct Highcharts format supplied by Wagtail
// This gets some further modifications
- this.apiConfig = JSON.parse(this.node.querySelector(`#config--${chartId}`).textContent);
- if (this.node.querySelector(`#annotations-values--${chartId}`)) {
+ this.uuid = this.node.dataset.highchartsUuid;
+
+ this.apiConfig = JSON.parse(
+ this.node.querySelector(`[data-highcharts-config="${this.uuid}"]`).textContent,
+ );
+ if (this.node.querySelector(`[data-highcharts-annotations-values="${this.uuid}"]`)) {
this.annotationsValues = JSON.parse(
- this.node.querySelector(`#annotations-values--${chartId}`).textContent,
+ this.node.querySelector(`[data-highcharts-annotations-values="${this.uuid}"]`).textContent,
);
}
@@ -48,7 +51,7 @@ class HighchartsBaseChart {
// Will only run once per page load
this.setCommonChartOptions();
- // Configure any annotations that have been specified
+ // Configure any annotations that have been specified (will be an empty array if no annotations are specified)
if (this.annotationsValues) {
this.configureAnnotations();
}