Skip to content

When including multiple charts, all use the same data. #3207

Open
@jaren-elizachat

Description

@jaren-elizachat

Preliminary Checks

Description

Using tailwind, add multiple charts with different data using the chart shortcode to the same page.

All charts will have the same data because the fetchChartJSON function is overwritten. That function should be included in the anonymous function.

I've fixed this locally by overriding the chart shortcode partial with this:

{{ $json := printf "./%s.json" (.Get "data") }}
{{ $id := delimit (shuffle (seq 1 9)) "" }}
<div id="chart-{{$id}}" class="chart"></div>
<script>
  (function() {
    async function fetchChartJSON() {
        console.debug('Hugo Blox fetching chart JSON...')
        const response = await fetch('{{$json}}');
        return await response.json();
    }

    let a = setInterval( function() {
      if ( typeof window.Plotly === 'undefined' ) {
        console.debug('Plotly not loaded yet...')
        return;
      }
      clearInterval( a );

      fetchChartJSON().then(chart => {
        console.debug('Plotting chart...')
        window.Plotly.newPlot('chart-{{$id}}', chart.data, chart.layout, {responsive: true});
      });
    }, 500 );
  })();
</script>

Reproduction Link

too lazy

Steps to Reproduce

1.see description
2.
3.
...

Expected Result

all charts use their respective data

Actual Result

all charts use the same data

What Hugo Module versions does your site use?

github.com/HugoBlox/hugo-blox-builder/modules/blox-tailwind v0.3.1

What operating system(s) are you seeing the problem on?

macOS

What browser(s) are you seeing the problem on?

No response

Which Hugo Blox template are you using?

its a partial, use any

What version of Hugo are you using?

0.136.5

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions