2016-04-22 102 views
4

Chartjsグラフの特定のグリッド線の線幅(または色)を変更する際には助けが必要です。特定の行のグリッド線幅を変更する方法

以下の例では、水平軸線のグリッド線の幅(または色を変更する)をy軸60で増やしたいと考えています。私はChartjsのドキュメントの中で解決策を見つけようとしましたが失敗しました。おそらくこれは現時点ではサポートされていないかもしれません。もしそうなら、誰でも私がこの機能を追加できるかどうかを知りたいと思います。

http://i.stack.imgur.com/nFB77.jpg

ありがとうございます!

あなたはスケールの描画機能を無効にするために、チャートを拡張し、あなたがしたい場所厚い/異なる色の線を引くことができ

答えて

3

プレビュー

enter image description here


スクリプト

Chart.types.Bar.extend({ 
    name: "BarAlt", 
    initialize: function(data){ 
     Chart.types.Bar.prototype.initialize.apply(this, arguments); 

     var originalScaleDraw = this.scale.draw; 
     this.scale.draw = function() { 
      originalScaleDraw.apply(this, arguments); 
      this.ctx.save(); 
      this.ctx.beginPath(); 
      this.ctx.lineWidth = this.gridLineWidth * 5; 
      this.ctx.strokeStyle = "rgba(120,120,220,1)"; 
      this.ctx.moveTo(Math.round(this.xScalePaddingLeft), this.calculateY(60)); 
      this.ctx.lineTo(this.width, this.calculateY(60)); 
      this.ctx.stroke(); 
      this.ctx.closePath(); 
      this.ctx.restore(); 
     } 
    } 
}); 

、その後

... 
new Chart(ctx).BarAlt(data); 

フィドル - http://jsfiddle.net/udojrq57/

+0

ありがとう、これは私が探していた、それは素晴らしい仕事を正確に何です。 – Billy

関連する問題