2016-04-04 9 views

Antwort

1

können Sie das Diagramm erweitern diese


Vorschau zu tun

enter image description here


Script

Chart.types.Line.extend({ 
    name: "LineAlt", 
    initialize: function(){ 
     // add some extra width the the y axis labels 
     this.options.scaleLabel = " " + this.options.scaleLabel; 
     Chart.types.Line.prototype.initialize.apply(this, arguments); 
    }, 
    draw: function(){ 
     Chart.types.Line.prototype.draw.apply(this, arguments); 

     ctx.save(); 
     ctx.fillStyle = '#fcc'; 
     // the fill should be under the text 
     ctx.globalCompositeOperation = "destination-over" 

     // draw background under x axis labels 
     Chart.helpers.each(this.scale.xLabels, function(label, index){ 
      var xPos = this.calculateX(index) + Chart.helpers.aliasPixel(this.lineWidth), 
      isRotated = (this.xLabelRotation > 0); 

      ctx.save(); 
      ctx.translate(xPos, (isRotated) ? this.endPoint + 12 : this.endPoint + 8); 
      ctx.rotate(Chart.helpers.radians(this.xLabelRotation) * -1); 
      var width = ctx.measureText(label).width; 
      // add a 4px padding on each side 
      // the height is set to 1.5 times the font size since there is no method to measure height easily 
      ctx.fillRect(-width/2 - 4, 0, width + 8, this.fontSize * 1.5); 
      ctx.restore(); 
     }, this.scale) 

     // draw background under y axis labels 
     var yLabelGap = (this.scale.endPoint - this.scale.startPoint)/this.scale.steps, 
      xStart = Math.round(this.scale.xScalePaddingLeft); 
     Chart.helpers.each(this.scale.yLabels,function(labelString, index){ 
        var yLabelCenter = this.endPoint - (yLabelGap * index); 
      var width = ctx.measureText(labelString).width; 
      // add some padding on the side - we don't need to increase the width because we use the width added by the extra space 
      ctx.fillRect(xStart - width - 4, yLabelCenter - this.fontSize * 1.5/2, width, this.fontSize * 1.5); 
     }, this.scale); 

     ctx.restore(); 
    } 
}); 

und dann

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

Fiddle - http://jsfiddle.net/e894g5qn/

+0

ich Ihre Bemühungen zu schätzen wissen, die Antwort zu geben, aber ich hatte gehofft, für etwas einfacher, oder vielleicht, dass die Option war schon da, in der Bibliothek . –

+1

Diese Option ist nicht in Version 1 der Bibliothek vorhanden (das ist die Version, mit der Sie die Daten betrachten). Prost! – potatopeelings

Verwandte Themen