Skip to content

Implementing javascript eCharts into niceGUI #3974

Closed Answered by HarryRogers0
HarryRogers0 asked this question in Q&A
Discussion options

You must be logged in to vote

Solution was reached by first loading the json file in via

# load static files
json_path= 'MAP.json'
app.add_static_files('/geojson', os.path.dirname(json_path))

then running the following javascript to ensure the json file was loaded before registering the map (this stops JavaScript error "Cannot read properties of undefined (reading 'regions')").

ui.add_body_html('''
<script>
    window.addEventListener('DOMContentLoaded', () => {
        // Fetch the local JSON file served by NiceGUI
        fetch('/MAP.json')
            .then((response) => response.json())
            .then((mapData) => {
                // Register the map with Echarts
                echarts.registerMap('MAP_NAME',…

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@HarryRogers0
Comment options

@falkoschindler
Comment options

@HarryRogers0
Comment options

Answer selected by HarryRogers0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
community question A question for the NiceGUI community
2 participants