Zero handling in Chart.js

I work with chart.js and draw a donut chart. I want to set the initial value of the total value to zero so that it can display the full "empty" graph. When I set the chart to zeros, it does not appear. I cannot find how it processes zeros in the developer documentation.

var kPoints = 000;
var mPoints = 000;
var tPoints = 000;
var cPoints = 000;
var doughnutData = [ {
    value : kPoints,
    color : "#FF8000"
}, {
    value : mPoints,
    color : "#99CC00"
}, {
    value : tPoints,
    color : "#0099CC"
}, {
    value : cPoints,
    color : "#333333"
}, ];
var ctx = $("#profileChart").get(0).getContext("2d");
var myDoughnut = new Chart(ctx).Doughnut(doughnutData);
+4
source share
2 answers

From reading the source code for, Chart.jsI found that he was trying to summarize each of the fields valuein his data source before displaying the chart (see usage segmentTotal here ).

, null ( ) . float :

var kPoints = null;
var mPoints = null;
var tPoints = null;
var cPoints = 1e-10;

( 3- ) , "" :

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: http://jsfiddle.net/MasterXen/6S9DB/3/

+6

. , " " ( ) , , 1 , " ".

0

Source: https://habr.com/ru/post/1542537/


All Articles