score:1
As bgse said in his answer you need to load library first. I suggest you use CDN as that way you don't need to download ChartJS library.
Secondly, you're writing some JS that may be executed before library is fetched to the page. So what would I add is:
<div class="card-body collapse in">
<div class="card-block chartjs">
<canvas id="line-chart" height="500"></canvas>
</div>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.6.0/Chart.min.js"></script>
<script src="https://code.jquery.com/jquery-3.2.1.min.js" integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4=" crossorigin="anonymous"></script>
<script>
$(document).ready(function(){
// Your JS code here
// ...
});
</script>
This way script code will execute when all JS is loaded.
score:4
First make sure the required JS is referenced in your template (or the template it extends).
Assuming you serve it from static/js
folder:
<head>
...
<script src='/static/js/Chart.bundle.min.js'></script>
...
</head>
Your script tag content looks mostly fine, just a little modification getting the context, and you appear to have a trailing });
that you need to remove:
<script>
// get context
var ctx = document.getElementById("line-chart").getContext("2d");
....
// Create the chart
var lineChart = new Chart(ctx, config);
// REMOVE THIS FROM THE END OF YOUR SCRIPT
//});
</script>
Source: stackoverflow.com
Related Query
- Adding Chart.js line chart to Jinja2/Flask html page from JS file
- Calling external Chartjs chart from a javascript file into HTML in Flask
- How to set the data of chart in angular which is taken from the backend nodejs api that is store in mongodb and showing on the html page
- Make Line Chart Dynamic From JSON File Using Chartjs
- Html5 web page with chartjs: loading an external json file and create a line chart
- How can I remove extra whitespace from the bottom of a line chart in chart.js?
- How to start the line graph from the left Y axis in a line/bar mixed chart (Chart.js)?
- How do I keep chart.js charts in one JS file, and not get errors when the ID from the JS file don't exist on one specific html page?
- ChartJS (React) Line Chart - How to show single tooltip with data and labels from 3 (multiple) dataset?
- chart.js add second line in a Line chart that starts from end of first line
- Adding line over stacked line chart with ChartJS
- How to make aspecific API call from within a Line Chart class in ReactJS using react-chartjs-2?
- I have 10 points inn x-axis, ranging [-25,-20,,-15,-10,0,10,20,30,40,50]. But I want my line chart to start from -15 of x-axis. How we can achieve?
- Passing an Array from a Flask view to the javascript code of another view
- Is there a convenient way to print values to a JS chart from a CSV file without converting it?
- How to change background color of labels in line chart from chart.js?
- Remove label from line chart - react-chartjs-2
- How do I display chart on my HTML page based on JSON data sent by Node JS
- Chart js with json file from url
- Adding data to line chart using addData() method in Chart.js
- Chart JS tooltip appears differently when set from script instead of html
- How to get line x value from Label chart js
- Is there any way to remove extra space and Horizontal line from Bar chart of Chart.js?
- ChartJS line chart or bar graph from a Java program
- How to add data dynamically to primevue Line chart from vuejs3?
- angular 4 line chart data is not showing data from http get
- How to fetch data from Json file on charts(bar-chart/pie chart etc) in angular?
- Loading data into chart on html page
- Multiple chart on one page using chart.js and Flask app
- Generate PDF from HTML page made with Bootstrap and ChartJS in Laravel
More Query from same tag
- How to create a charts in Razor Pages pulling data from the database?
- Chart.js multiple columns of data for the same label
- ChartJS - Horizontal Stacked Bar Chart Tooltip being cut off by Bottom of Canvas
- Can i use crosshairs with OHLC/candlestick charts using ChartJS
- Is it possible to get the assigned ref name in a component? Vue.js
- Can't Customize Chart.js
- how to show bar chart for every product
- JQuery calling global from local
- Chart.js creating multiple Charts in Angular in same Component
- Chart.js in AngularJS tabset does not render
- How do I display chart on my HTML page based on JSON data sent by Node JS
- Need help adding decimals to yaxis values
- chartkick chart.js change colour of axis and colour of axis title
- How to create multiple y-axis time series chart
- How to make the last item on the chart js active?
- How to use data from database for chart.js (bubble chart) with Ajax/JSON method?
- Chart.js plot not aligned with xAxis labels
- Legend for only specific datasets - chart.js
- ChartJS chart is bugged after adding new data
- Chartjs Bar Chart add background color to value labels
- Show statistics in my diagram (php mysqli)
- Replace Chart.js Data during `onClick` causes _meta error
- Chart.js Point image on hover
- How do I create a chartjs bar chart?
- Aligning zero on y axis to the labels on x axis of line chart in chartjs
- Tooltip is not displayed when using annotation in ChartJs
- Import data from Excel and use in Chart.js
- How to change orientation of the main y-axis label in charts.js?
- Replace a Canvas Pie Chart Onclick
- How to set Chart.js axis minumum to 0?