]> git.ipfire.org Git - thirdparty/Chart.js.git/commitdiff
Add option to toggle grid vertical/horizontal lines
authorFrancisco Neves <fntneves@gmail.com>
Mon, 8 Sep 2014 15:10:45 +0000 (16:10 +0100)
committerFrancisco Neves <fntneves@gmail.com>
Mon, 8 Sep 2014 15:10:45 +0000 (16:10 +0100)
src/Chart.Bar.js
src/Chart.Core.js
src/Chart.Line.js

index fafe74a49d85fefc7848a99af9e3f980ec342332..87fb26ddc405267419abcaa749b76435ee3340cc 100644 (file)
                //Number - Width of the grid lines
                scaleGridLineWidth : 1,
 
+               //Boolean - Whether to show horizontal lines (except X axis)
+               scaleShowHorizontalLines: true,
+
+               //Boolean - Whether to show vertical lines (except Y axis)
+               scaleShowVerticalLines: true,
+
                //Boolean - If there is a stroke on each bar
                barShowStroke : true,
 
                                font : helpers.fontString(this.options.scaleFontSize, this.options.scaleFontStyle, this.options.scaleFontFamily),
                                lineWidth : this.options.scaleLineWidth,
                                lineColor : this.options.scaleLineColor,
+                               showHorizontalLines : this.options.scaleShowHorizontalLines,
+                               showVerticalLines : this.options.scaleShowVerticalLines,
                                gridLineWidth : (this.options.scaleShowGridLines) ? this.options.scaleGridLineWidth : 0,
                                gridLineColor : (this.options.scaleShowGridLines) ? this.options.scaleGridLineColor : "rgba(0,0,0,0)",
                                padding : (this.options.showScale) ? 0 : (this.options.barShowStroke) ? this.options.barStrokeWidth : 0,
        });
 
 
-}).call(this);
\ No newline at end of file
+}).call(this);
index 03b99b45a582e69ae57ea79f3ed3e5bbae3bb0d1..e514ccf706a7c020f212a19bfb055ff3a58b63fb 100755 (executable)
                                ctx.font = this.font;
                                each(this.yLabels,function(labelString,index){
                                        var yLabelCenter = this.endPoint - (yLabelGap * index),
-                                               linePositionY = Math.round(yLabelCenter);
+                                               linePositionY = Math.round(yLabelCenter),
+                                               drawHorizontalLine = this.showHorizontalLines;
 
                                        ctx.textAlign = "right";
                                        ctx.textBaseline = "middle";
                                        if (this.showLabels){
                                                ctx.fillText(labelString,xStart - 10,yLabelCenter);
                                        }
-                                       ctx.beginPath();
+
+                                       // This is X axis, so draw it
+                                       if (index === 0 && !drawHorizontalLine){
+                                               drawHorizontalLine = true;
+                                       }
+
+                                       if (drawHorizontalLine){
+                                               ctx.beginPath();
+                                       }
+
                                        if (index > 0){
                                                // This is a grid line in the centre, so drop that
                                                ctx.lineWidth = this.gridLineWidth;
 
                                        linePositionY += helpers.aliasPixel(ctx.lineWidth);
 
-                                       ctx.moveTo(xStart, linePositionY);
-                                       ctx.lineTo(this.width, linePositionY);
-                                       ctx.stroke();
-                                       ctx.closePath();
+                                       if(drawHorizontalLine){
+                                               ctx.moveTo(xStart, linePositionY);
+                                               ctx.lineTo(this.width, linePositionY);
+                                               ctx.stroke();
+                                               ctx.closePath();
+                                       }
 
                                        ctx.lineWidth = this.lineWidth;
                                        ctx.strokeStyle = this.lineColor;
                                        var xPos = this.calculateX(index) + aliasPixel(this.lineWidth),
                                                // Check to see if line/bar here and decide where to place the line
                                                linePos = this.calculateX(index - (this.offsetGridLines ? 0.5 : 0)) + aliasPixel(this.lineWidth),
-                                               isRotated = (this.xLabelRotation > 0);
+                                               isRotated = (this.xLabelRotation > 0),
+                                               drawVerticalLine = this.showVerticalLines;
 
-                                       ctx.beginPath();
+                                       // This is Y axis, so draw it
+                                       if (index === 0 && !drawVerticalLine){
+                                               drawVerticalLine = true;
+                                       }
+
+                                       if (drawVerticalLine){
+                                               ctx.beginPath();
+                                       }
 
                                        if (index > 0){
                                                // This is a grid line in the centre, so drop that
                                                ctx.lineWidth = this.lineWidth;
                                                ctx.strokeStyle = this.lineColor;
                                        }
-                                       ctx.moveTo(linePos,this.endPoint);
-                                       ctx.lineTo(linePos,this.startPoint - 3);
-                                       ctx.stroke();
-                                       ctx.closePath();
+
+                                       if (drawVerticalLine){
+                                               ctx.moveTo(linePos,this.endPoint);
+                                               ctx.lineTo(linePos,this.startPoint - 3);
+                                               ctx.stroke();
+                                               ctx.closePath();
+                                       }
 
 
                                        ctx.lineWidth = this.lineWidth;
index 0b3079ffe11237700a08b9d8bc232a7abd6dcda2..34ad85b4d0ae1ae96b40b506385ae42547ef6063 100644 (file)
                //Number - Width of the grid lines
                scaleGridLineWidth : 1,
 
+               //Boolean - Whether to show horizontal lines (except X axis)
+               scaleShowHorizontalLines: true,
+
+               //Boolean - Whether to show vertical lines (except Y axis)
+               scaleShowVerticalLines: true,
+
                //Boolean - Whether the line is curved between points
                bezierCurve : true,
 
                                font : helpers.fontString(this.options.scaleFontSize, this.options.scaleFontStyle, this.options.scaleFontFamily),
                                lineWidth : this.options.scaleLineWidth,
                                lineColor : this.options.scaleLineColor,
+                               showHorizontalLines : this.options.scaleShowHorizontalLines,
+                               showVerticalLines : this.options.scaleShowVerticalLines,
                                gridLineWidth : (this.options.scaleShowGridLines) ? this.options.scaleGridLineWidth : 0,
                                gridLineColor : (this.options.scaleShowGridLines) ? this.options.scaleGridLineColor : "rgba(0,0,0,0)",
                                padding: (this.options.showScale) ? 0 : this.options.pointDotRadius + this.options.pointDotStrokeWidth,
        });
 
 
-}).call(this);
\ No newline at end of file
+}).call(this);