2017-10-09 3 views
1

私はChart.jsと作業しています。私は特定の色を持つ単一のデータラインを持っています。私はこれらのデータラインのポイントを異なる色にしたい。文書によると、あなたはChart.defaults.global.elements.point.backgroundColorChart.jsデータの背景色が上書き点の背景色です

var ctxLine = document.getElementById("lineChart").getContext('2d'); 
lineChart = new Chart(ctxLine, { 
type: 'line', 
data: { 
    labels: dates, 
    datasets: [{ 
      data: ['...'], 
      backgroundColor: "rgba(52,152,219,0.4)" 
     }] 
}, 
options: { 
    elements: { 
     point: { 
       borderColor: "rgb(255,255,0)", 
       backgroundColor: "rgb(255,0,0)" 
      } 
     }      
    } 
}); 

point.borderColorが正常に動作しているが、私が最初にbackgroundColorフィールドを削除する場合point.backgroundColorのみが働いていると、これを行うことができます。

答えて

0

私は自分で解決策を見つけました。私はV2.0を使用していますが、名前のプロパティが存在する

chart.jsの異なるバージョンが存在することを認識しませんでしたpointBackgroundColor

var ctxLine = document.getElementById("lineChart").getContext('2d'); 
lineChart = new Chart(ctxLine, { 
type: 'line', 
data: { 
    labels: dates, 
    datasets: [{ 
      data: ['...'], 
      backgroundColor: "rgba(52,152,219,0.4)", 
      pointBackgroundColor: "#fff" 
     }] 
} 
}); 
0

Chart.defaults.global.elements.point.backgroundColorのように見えるのは1つの色文字列だけです。

私は異なる色の点を持つことは可能ではないと思います。 Here is the documentation page for it.

アレイをbackgroundColorプロパティにプラグインしようとしましたが、デフォルトでは別の色になりました。 Have a look at this fiddle、あなたが遊びたい場合。

いつでも機能リクエストを送信できます。