From: Rahul Vaidya Date: Thu, 16 Apr 2015 08:23:09 +0000 (-0700) Subject: Added a scaleBackgroundColors configuration option for Radial charts, to add a backgr... X-Git-Tag: v1.1.0~51^2~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7045fdbb5afeb377b047464e6388c0f7ce46306f;p=thirdparty%2FChart.js.git Added a scaleBackgroundColors configuration option for Radial charts, to add a background color for each axis in the chart. --- diff --git a/src/Chart.Core.js b/src/Chart.Core.js index a86fe4536..e51d4d4b2 100755 --- a/src/Chart.Core.js +++ b/src/Chart.Core.js @@ -2011,6 +2011,23 @@ ctx.lineTo(outerPosition.x, outerPosition.y); ctx.stroke(); ctx.closePath(); + + if (this.backgroundColors) { + var previousOuterPosition = this.getPointPosition(i === 0 ? this.valuesCount - 1 : i - 1, this.calculateCenterOffset(this.max)); + var nextOuterPosition = this.getPointPosition(i === this.valuesCount - 1 ? 0 : i + 1, this.calculateCenterOffset(this.max)); + + var previousOuterHalfway = { x: (previousOuterPosition.x + outerPosition.x) / 2, y: (previousOuterPosition.y + outerPosition.y) / 2 }; + var nextOuterHalfway = { x: (outerPosition.x + nextOuterPosition.x) / 2, y: (outerPosition.y + nextOuterPosition.y) / 2 }; + + ctx.beginPath(); + ctx.moveTo(this.xCenter, this.yCenter); + ctx.lineTo(previousOuterHalfway.x, previousOuterHalfway.y); + ctx.lineTo(outerPosition.x, outerPosition.y); + ctx.lineTo(nextOuterHalfway.x, nextOuterHalfway.y); + ctx.fillStyle = this.backgroundColors[i]; + ctx.fill(); + ctx.closePath(); + } } // Extra 3px out for some label spacing var pointLabelPosition = this.getPointPosition(i, this.calculateCenterOffset(this.max) + 5); diff --git a/src/Chart.Radar.js b/src/Chart.Radar.js index 134fd2d02..f48dc4bdb 100644 --- a/src/Chart.Radar.js +++ b/src/Chart.Radar.js @@ -174,6 +174,7 @@ showLabels: this.options.scaleShowLabels, showLabelBackdrop: this.options.scaleShowLabelBackdrop, backdropColor: this.options.scaleBackdropColor, + backgroundColors: this.options.scaleBackgroundColors, backdropPaddingY : this.options.scaleBackdropPaddingY, backdropPaddingX: this.options.scaleBackdropPaddingX, lineWidth: (this.options.scaleShowLine) ? this.options.scaleLineWidth : 0,