"Utilizing JSON data to generate a visual representation through a chart

I am attempting to generate a graph in chart.js by utilizing data extracted from an SQL database using python. My current approach involves creating a JSON file in python and then loading it in javascript (although I am uncertain if this is the most optimal method).

Below is the snippet of code I am working with:

{% extends "layout.html" %}

{% block head %}
    <script src="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="6a09020b181e4400192a584453445e">[email protected]</a>/dist/Chart.min.js"></script>
{% block title %}
    Graph
{% endblock %}

{% block main %}
    <canvas id="chart" width="300" height="300"></canvas>
    <script>
        const labels = [];
        const ycoordinate = [];
        chartIt();
    
        async function chartIt(){
            await getData();
            const ctx = document.getElementById('chart').getContext('2d');
            const myChart = new Chart(ctx, {
                type: 'line',
                data: {
                    labels: labels,
                    datasets:[{
                       data: ycoordinate
                    }],
                },
                options: {}});
        }
    
        async function getData(){
            const response = await fetch('data.json');
            const data = await response.text();
            console.log(data);
            const labels = data.map((x) => x.date);
            const ycoordinate = data.map((x) => x.mass);
        }
    </script>
{% endblock %}

Upon running this code, I encounter a 500 internal server error at line 68, within the template {% endblock %}

jinja2.exceptions.TemplateSyntaxError: Unexpected end of template. Jinja was looking for the following tags: 'endblock'. The innermost block that needs to be closed is 'block'.

Additionally, my console displays Mixed content: load all resources via HTTPS to improve the security of your site

Answer №1

Make sure to close the head block properly on the 5th line of your code example by inserting {% endblock %} for correct syntax.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Show only the selected option with jQuery's on change event and disable or remove the other options

My goal is to make it so that when a user selects an option from a dropdown menu, the other options are disabled or hidden. For example, if option "1" is selected, options "2", "3", and "4" will be removed: <div class="abc"> <div class="xyz"> ...

issue with data binding in ons-dialog

Utilizing an ons-dialog to display a popup prompting the user to sign up for a newsletter. I have set a 3-second timeout to prevent users from immediately closing the prompt without reading it or waiting. I aim to initially show the dialog with the ' ...

Transfer your focus to the following control by pressing the Enter key

I came across a project built on Angular 1.x that allows users to move focus to the next control by pressing the Enter key. 'use strict'; app.directive('setTabEnter', function () { var includeTags = ['INPUT', 'SELEC ...

Is there something else I should consider while implementing onBlur?

I am currently working on implementing form validation for a React form that I have developed. The process involves using an onChange event to update the state with the value of each text field, followed by an onBlur validation function which checks the va ...

Guide to importing Bootstrap 5 bundle js using npm

Having some issues with implementing Bootstrap5 and NPM. The website design is using bootstrap, which works fine, but not all the JavaScript components (dropdowns, modals, etc). I want to figure out how to import the Bootstrap JS bundle without relying on ...

The JavaScript alert box cannot retrieve data from the PHP parent page

What am I missing? Here is the JavaScript code snippet: <script language="javascript"> function openPopup(url) { window.open(url,'popupWindow','toolbar=no,location=no,directories=no,status=no, menubar=no,scrollbars=n ...

Expanding and collapsing multiple tables in Material-UI

I'm currently working on creating a collapsible table using MaterialUI. At the moment, all my slides have collapses but they are connected to one state for "open", so when I open one slide, all the other slides also open. Here is an example sandbox t ...

Sharing JavaScript code between Maven modules can be achieved by following these steps

My Maven project has a unique structure that includes: "Base" module -- containing shared Java files -- should also include shared JavaScript files Module 1 -- using shared Java files as a Maven dependency -- should utilize shared JavaScript files throug ...

json Exploring Input/Output Operations in SQL Server

When I insert serialized data into my SQL server, for example: "{\"Array\":\"Service\",\"Setting\":[{\"Id\":1},{\"Id\":2},{\"Id\":3},{\"Id\":4}]}" I then retrieve this value from the d ...

Progress bar display not available

I have recently developed a JavaScript quiz application and included a progress bar feature. While it works flawlessly offline on my laptop, I encountered an issue when uploading the files to Codepen.io - the progress bar fails to display. I would appreci ...

Mastering the art of properly connecting Angular HttpPromise

Recently, I encountered an angular Service containing a crucial function: service.getItemByID = function(id) { var hp = $http({method: "GET", url: "service/open/item/id", headers: {"token": $rootScope.user.token}, para ...

Tips for assigning focus properties inside VueJS components

Within my component child Input: <template> <div class="basic-input-outer" :style="styles"> <p class="paragraph-small">{{ title }}</p> <input ref="name" :type="type" cla ...

Choose a row in an Angular ngGrid upon loading the page

My question is in relation to this inquiry How can I retrieve selected rows from ng-grid? Check out the plunker sample - http://plnkr.co/edit/DiDitL?p=preview Upon page load, I am looking to have a row pre-selected without relying on 'ngGridEventDa ...

In order to utilize the componentDidUpdate lifecycle method, I passed props to the Outlet component while nesting it

I am currently using react-router-v6 and encountering some issues with my configuration. I have implemented nested routing with layouts according to the following settings. App.js <BrowserRouter> <Routes> <Route exact pat ...

"Set a timeout for an HTML markup to be displayed in an AJAX

Is there a way to automatically hide the success message that appears after an AJAX request is successful? For example, after 2 seconds of displaying the message, I want it to disappear. Here's the code I have: $.ajax({ url : 'process/regis ...

The HTML generated by Selenium using Javascript is still missing some elements, despite accessing the document.body.innerHTML

Attempting to retrieve the HTML from a webpage that undergoes modification by JavaScript post-loading. Followed directions in this guide, executing the command below in my Python script after initial page load: html = browser.execute_script("return docume ...

Error: Invalid JSON format detected at the beginning of the data, causing a SyntaxError at line 1, column 1

My goal is to retrieve data from an Oracle database located inside a Docker container using a SQL query and display the response as a dropdown in a web interface. Here is the server-side GET method: app.get('/api/getDropdownOptions', (req, res) = ...

How to retrieve the third party child component within a Vue parent component

Within my example-component, I have integrated a third-party media upload child component called media-uploader: <example-component> <form :action= "something"> // Other input types <media-upload :ref="'cover_up ...

Ways to identify when a specific react component has been clicked

Currently working on developing a klondike game with 4 empty stacks at the start of the game. The initial page layout resembles the first image provided in the link. I am facing an issue where I cannot determine which component was clicked when clicking on ...

Utilize the NPM Python Shell Callback Feature within Electron

I have a Python script that reads RFID tags when executed in the Python shell. Everything works fine with the script, but I'm facing an issue where I want to display "testing" using console.log() after the script is executed (when the tag is placed ov ...