score:4
Accepted answer
The issue is, you are using ChartJS v1, but are constructing the chart as it is for ChartJS v2.
You should be using the latest version of ChartJS, which is ChartJS v2. Here is the CDN Link for it.
and here's the working version of your code ...
const documentStats = document.getElementById('document_stats').getContext('2d');
const statsArr = {
commentary: 0,
variants: 0
};
const chartData = {
labels: [],
datasets: [{
data: [],
borderWidth: 5,
backgroundColor: ['#2098d4', '#f8da50'],
hoverBackgroundColor: ['#148fb5', '#f2d02b'],
}],
};
const result = {
"id": "13",
"doc_name": "Confidentiality Agreement - (Non-Disclosure Agreement)",
"short_name": "Comprehensive One-Directional",
"long_description": "This agreement is intended to be used by a business when providing confidential information in one direction from the business to the recipient party. This agreement is comprehensive and includes various protections for the party disclosing the confidential information. This agreement can be used in various contexts eg. hiring a contract worker, or providing confidential information for a limited scope project.",
"overview": {
"name": "NDA",
"summary": "An NDA is a non-disclosure agreement, also known as a confidentiality agreement. The person receiving confidential information agrees not to share that information with others and not to use the information except as authorized by the person disclosing the information.",
"usage": "This document could be used in any situation where confidential information is shared, including employment/consulting relationships, potential investors, potential business relationships, potential mergers and acquisitions, potential manufacturers of a product etc.",
"who_signs": "Both the person receiving the information (‘receiving party’) and the person disclosing the information (‘disclosing party’) will sign the NDA. Sometimes certain affiliates or representatives of the receiving and disclosing parties will also be required to sign the NDA.",
"description": "Non-disclosure clauses can range in length from a clause contained in an agreement (eg. an employment agreement), to a lengthy and detailed stand-alone contract.\n\n The NDA must contain a general duty to not disclose the confidential information and a prohibition of use of the confidential information except for the purpose permitted in the NDA. The confidential information and the permitted purpose must be defined, and should be appropriate to the unique needs of the situation. The NDA should also include a list of exclusions from the obligation not to disclose, as well as a description of persons to whom the receiving party can disclose the information eg. authorized representatives.\n\n Many NDA’s contain further restrictive covenants designed to protect the disclosing party. These may include a non-competition clause, a non-solicitation clause, a non-circumvention clause or an expanded non-use clause.",
"core_elements": "The core elements include: definition of confidential information, general duty not to disclose, confidential information exclusions, use limited to purpose, definition of use or purpose, authorized representatives, term, termination, remedies, return or destruction of confidential information.\n\n Some additional clauses include handling of confidential information and safeguarding requirements, ownership of confidential information and its derivatives, no representation as to accuracy of confidential information, confidentiality of agreement itself, injunctive relief, liability for actions of representatives, IP assignment and transfer of moral rights, no conflict with another agreement, non-competition, non-solicitation, non-circumvention, non-use, no obligation to enter into a business relationship.",
"related_documents": ""
},
"status": [{
"label": "commentary",
"count": "127"
}, {
"label": "variants",
"count": "256"
}]
};
// TODO: Add permissions later. Hide from view later.
result.status.filter((v, i) => { //debugger;
statsArr[v.label] = v.count;
$(`.${result.status[i].label.toLowerCase()}_stats span`).text(result.status[i].count);
});
// for Chart legend
chartData.labels = Object.keys(statsArr);
// for charts data
chartData.datasets[0].data = Object.values(statsArr);
// And for a doughnut chart
new Chart(documentStats, {
type: 'doughnut',
data: chartData,
maintainAspectRatio: false,
responsive: true,
options: {
legend: {
display: false,
position: 'left'
},
},
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.6.0/Chart.min.js"></script>
<canvas width="200" height="200" id="document_stats"></canvas>
Source: stackoverflow.com
Related Query
- Chartjs not rendering chart and no error thrown
- Chartjs (Non Vue) Not Rendering Graph Chart inside V-if/V-show
- Chart.js Date and Time Bar Chart Not Rendering - Line Works Though
- VueJs and ChartJs - Chart is responsive in width, but not height?
- Chart not rendering with pug/jade and nodejs
- ChartJS line chart x = y not rendering astraight line
- ChartJS on NodeJS: error Chart is not defined
- Chart not rendering on ChartJS
- Chartjs chart not rendering with pug template
- Reproduce Error in Chartjs v2 Polar chart not plotting all supplied data
- I am using chart js to draw a chart. I did everything right but i don't know why the x axis and y axis label is not comming in chart. code below
- Chart.js returns a console error and does not display the chart when using variables as data input
- 'require is not defined' error when attempting to use chartjs in javascript code
- ReferenceError: Chart is not defined - chartjs
- Chart.js: bar chart first bar and last bar not displaying in full
- ChartJS canvas not displaying rgba colors in IE, Safari and Firefox
- react-chartjs-2 with chartJs 3: Error "arc" is not a registered element
- Chartjs 2 - Stacked bar and unstacked line on same chart with same y axis
- TimeSeries scale in ChartJS 3.0.2. brings error "This method is not implemented: either no adapter can be found or an incomplete integration was ..."
- chartjs datalabels change font and color of text displaying inside pie chart
- show label in tooltip but not in x axis for chartjs line chart
- chartjs + Angular6 is not showing charts or any error
- chartjs - top and bottom padding of a chart area
- Category scale on Y-axis and time on x-axis in bubble chart in Chartjs
- Chart.js: width and height of a pie chart not respected
- ChartJS Line chart cut off at the top and bottom
- ChartJS line chart drag and zoom
- Pie chart is not getting rendered in ChartJS
- Chart JS not rendering on iOS devices
- ChartJS (React) Line Chart - How to show single tooltip with data and labels from 3 (multiple) dataset?
More Query from same tag
- Can't get Chart.js to run in a Vue.js component
- Hide Y-axis labels when data is not displayed in Chart.js
- UnitStepSize for regular time interval with Chartjs
- How to print a chart rendered by code
- Uncaught TypeError: Cannot read property 'draw' of undefined for object scale
- Chart Js Negative Scale
- Chart.js stacked bar chart text on top of the stacked bars
- Legend option destroys pie chart in Chart.js
- Is there any way to change the font size of labels in bar chart in Chart.js v3?
- How to make dynamic chart js using JSON in Codeigniter?
- Chartjs / ng2-charts line on hover does not work
- chartjs: trying to rotate the y-Axis label
- Does iFrame have any events suitable for when a JavaScript & HTML page are embedded in modal(Bootstrap)
- (Chart.js 3.7.0) change position of x-axis ticks to alternate between each tick?
- Place tooltip on the outer side of the doughnut chart
- Change border color on legend in Chart.js
- Vertical lines for custom events and notes
- angular chart.js not resizing (shinking) in a flexbox
- Add new line in es6 inside a doughnut chart
- Chart JS - Change the color of the last element in a Bar Chart
- Growing chart value - chart.js
- How to change bar width individually in chartjs?
- Chart disappears just after finishing animation
- Updating chart.js based on selections from dropdown
- charts are not being show with wicked_pdf
- Load data into chartjs using promises in vue.js
- Chart.js javascript from db stopped working after adding axes
- ChartJS tooltip values aren't matching the data after updating multiple charts
- How to pass a nested function to an HTML button and Dropdown menu
- remove strikethrough behavior in chart.js bar chart