score:7
From reading the source code for Chart.js
I've found that the it tries to sum each of the value
fields in its datasource before rendering the chart (see the use of segmentTotal
here).
To workaround this, use null
for all the values and set one (or more) of the data points to a very small, near zero value. I've used a float notation here for one of the values:
var kPoints = null;
var mPoints = null;
var tPoints = null;
var cPoints = 1e-10;
After that, the example below re-renders the chart (after a 3 second delay) with different data values to show a case of the values updating from the default "dark" chart to a filled out version:
setTimeout(function () {
// Generate a new, random value for each of the data points
doughnutData.forEach(function (item) {
item.value = Math.floor((Math.random() * 10) + 1);
});
var ctx = $("#profileChart").get(0).getContext("2d");
var myDoughnut = new Chart(ctx).Doughnut(doughnutData);
}, 3000);
JSFiddle Example: http://jsfiddle.net/MasterXen/6S9DB/3/
score:0
Keep a running total of the values when building the doughnut data. If there are zero data points, or the total value of all data points is zero, then simply inject an extra dummy point with a label like "No Data" along with an either imperceptible (near-zero) value or a dummy value like 1. In either case, you'll end up with a valid chart with a single category like "No Data".
Source: stackoverflow.com
Related Query
- Chart.js zeros handling
- ChartJS:align zeros on chart with multi axes
- ChartJS - handling of overlapping points in line chart
- what is wrong with my code ? java script chart position
- How to print a chart rendered by code
- VueJS + Chartjs - Chart only renders after code change
- How do I destroy/update Chart Data in this chart.js code example?
- getting additional value fields from data source for dx.chartjs doughnut chart
- 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
- Getting the HTML code of a chart created by chart.js
- How to run Chart.js samples using source code
- how to not repeat code while creating multiple charts in chart js
- Set height of chart in Chart.js
- Dynamically update values of a chartjs chart
- How to add text inside the doughnut chart using Chart.js?
- How to clear a chart from a canvas so that hover events cannot be triggered?
- In Chart.js set chart title, name of x axis and y axis?
- Limit labels number on Chart.js line chart
- Chart.js - How to set a line chart dataset as disabled on load
- chart js 2 how to set bar width
- How can labels/legends be added for all chart types in chart.js (chartjs.org)?
- Chartjs Bar Chart showing old data when hovering
- Chart.js Show labels on Pie chart
- Chart Js Change Label orientation on x-Axis for Line Charts
- Chart area background color chartjs
- Chart.js - Increase spacing between legend and chart
- Converting Chart.js canvas chart to image using .toDataUrl() results in blank image
- Draw horizontal line on chart in chart.js on v2
- How can I create a horizontal scrolling Chart.js line chart with a locked y axis?
- Remove the vertical line in the chart js line chart
More Query from same tag
- How do you disable tooltips in ember-cli-chart?
- Prime NG Customise tool tip on Bar Chart
- ChartJS V3 borderRadius only works on top
- Line chart is drawing before first point in Chart.js
- Is there any way to get y of specific x which not belongs to the dataset in Chart.js graph?
- How to remove header square from chart.js?
- chart.js horzontalBar Stacked and Grouped - data not showing - a bug?
- Chart.js: Disable Y-Axis, when graph is disabled via Legend
- How can I add user inputted values to my chart.js line graph?
- How to increase the spacing between labels and the chart
- Chart.js horizontalBar customization
- How to use excess vertical space in stacked bar chart?
- How can I change the starting point of horizontal bars in Charts.js
- Draw y-axis inside the graph area with chart js
- chart.JS time axis labels should be just in hours format
- How to make aspecific API call from within a Line Chart class in ReactJS using react-chartjs-2?
- Stepped line with null values in chart.js
- display multiple charts angular.js chart.js
- chart.js data forming though the API dynamically based on selects
- How can I trigger the hover mode from outside the chart with charts.js 2?
- Dynamically create dataset objects for multi-line graphing, using pre-defined dataset object arrays (JavaScript / Chart.js)
- Show values in Chart.js Pie chart parts
- Chart.js - Same min and max value of two charts
- Pass List of Objects as data
- chart.js cuts data points to half
- Meteor with Chart js cannot read property ‘getContext’ of null only AFTER new document in collection?
- Display labels on bar chart using Chart.js
- How to get any y value for specified x in chart.js?
- How to set equal width between ticks - chartjs
- Chart.js remove shadow from line chart