第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

當(dāng)數(shù)據(jù)為0時,如何使chartJs堆積條總是四舍五入?

當(dāng)數(shù)據(jù)為0時,如何使chartJs堆積條總是四舍五入?

慕的地8271018 2022-10-08 18:09:16
我想出了這個小提琴:https : //jsfiddle.net/2s09hqLu/ 它有我想要的堆疊圓角圖表。但問題是當(dāng)數(shù)據(jù)數(shù)組中的值為 0 時。它不會使它四舍五入。我總是希望它是四舍五入我該怎么做?data: [20, 5, 0, 15, 12, 13]正如您在黃色上看到的那樣,它的平面不是圓形的。我該如何解決這個問題?
查看完整描述

3 回答

?
炎炎設(shè)計

TA貢獻1808條經(jīng)驗 獲得超4個贊

我在下面嘗試過,并且可以完美地處理任何數(shù)量的數(shù)據(jù)集。


var lastVisible;

  var datasetsLength = this._chart.data.datasets.length;

  this._chart.data.datasets.map((e,index)=>{

    lastVisible=datasetsLength-1;

    //to find the depth of datasets and get non-zero value

    for(var i=lastVisible;i>0;i--){

    if(!this._chart.getDatasetMeta(i).hidden){

      if(this._chart.data.datasets[i].data[this._index] != 0){

        lastVisible = i;

        break;

      }

    }

    } 

  })


查看完整回答
反對 回復(fù) 2022-10-08
?
慕蓋茨4494581

TA貢獻1850條經(jīng)驗 獲得超11個贊

我已經(jīng)更新了您的 Fiddle 唯一行號118: https ://jsfiddle.net/r7hvn2ox/

從:

if (rounded){

至:

if (rounded || this._chart.data.datasets[1].data[this._index] == 0) {

我知道它對 2 個數(shù)據(jù)集的修復(fù):[{}, {}] 條,但它可以在任何數(shù)據(jù)集的值以及本示例中完美地工作。


查看完整回答
反對 回復(fù) 2022-10-08
?
肥皂起泡泡

TA貢獻1829條經(jīng)驗 獲得超6個贊

rounded如果它呈現(xiàn)特定項目,您可以向變量添加額外的表達式。這不是最好的方法。


var rounded = this._datasetIndex  === lastVisible || this._index === 2;

或者,您可以比較每個數(shù)據(jù)集中的值


var cond = false;


if(this._datasetIndex === 0) {

  var datasets = this._chart.data.datasets;

  var dataset = datasets[this._datasetIndex];

  var currentData = dataset.data[this._index];

  var nextData = datasets[this._datasetIndex + 1].data[this._index]

  cond = currentData !== 0 && nextData === 0;

}


var rounded = this._datasetIndex  === lastVisible || cond;


查看完整回答
反對 回復(fù) 2022-10-08
  • 3 回答
  • 0 關(guān)注
  • 113 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號