2017-10-13 138 views
1

Chart.js沒有顯示圖例。我使用2.4.0版本,並且在我的網站中包含Chart.bundle.min.js腳本。Chart.js沒有顯示圖例

定義了所有變量,如lineaRoja,puntos,MuPu,並正確顯示數據。

問題是與Falla balanceadaMu y Pu aplicadosDiagrama M-P與他們各自的顏色沒有顯示的傳說。當我將鼠標懸停在點上時,只有工具提示顯示。

var canvas = document.getElementById(domId); 
var ctx = canvas.getContext("2d"); 
var lineChart = new Chart(ctx, { 
     type: 'line', 
     data: { 
      datasets: [{ 
       label: 'Diagrama M-P', 
       data: puntos 
      }, { 
       label: 'Falla balanceada', 
       backgroundColor: 'rgba(0,0,0,0)', 
       borderColor: 'rgba(130,0,0,0.6)', 
       data: [{ x: 0, y: 0}, { x: lineaRoja[0], y: lineaRoja[1] }], 
       borderDash: [10, 5] 
      }, { 
       type: 'scatter', 
       data: MuPu, 
       fill: false, 
       showLine: false, 
       backgroundColor: 'rgba(0,130,0,0.6)', 
       label: 'Mu y Pu aplicados', 
       pointRadius: 6 

      }] 
     }, 
     options: { 
      animation: { duration: 0 }, 

      scales: { 
       xAxes: [{ 
        type: 'linear', 
        position: 'bottom', 
        scaleLabel: { 
        display: true, 
        labelString: 'Ton' 
        } 
       }], 
       yAxes: [{ 
       scaleLabel: { 
        display: true, 
        labelString: 'Ton m' 
       }, 
       ticks: { 
        min: 0, 
        beginAtZero: true 
       } 
      }] 
      } 
     } 
    }); 

回答

1

解決了,我用的是引導模板有這個代碼的地方在它的.js文件

Chart.defaults.global.legend = { 
    enabled: false 
}; 
0

您可以選擇添加此。

legend: { 
    display: true 
} 
+0

yes我知道@loki但在這個答案沒有解釋。 –