2016-10-20 3 views

答えて

0

ありがとうございます。

このタイプのカスタマイズは既にラインチャートで行われていますが、hereと表示することもできます。

しかし、残念ながらこの質問は終了しました。

forループ

// Define your label code here 
    // Put more code for label if require... 
    let lbl = UILabel() 
    lbl.text = "\(e.values)" 
    lbl.drawTextInRect(barRect) 

4内のコードの下に置く)

internal func drawDataSet(context context: CGContext, dataSet: BarChartDataSet, index: Int) 

3検索BarChartRenderer

2)に行くバーチャート

1)にラベルを追加するには)以下の機能をすべて表示することもできます

internal func drawDataSet(context context: CGContext, dataSet: BarChartDataSet, index: Int) 
    { 
     guard let dataProvider = dataProvider, barData = dataProvider.barData else { return } 

     CGContextSaveGState(context) 

     let trans = dataProvider.getTransformer(dataSet.axisDependency) 

     let drawBarShadowEnabled: Bool = dataProvider.isDrawBarShadowEnabled 
     let dataSetOffset = (barData.dataSetCount - 1) 
     let groupSpace = barData.groupSpace 
     let groupSpaceHalf = groupSpace/2.0 
     let barSpace = dataSet.barSpace 
     let barSpaceHalf = barSpace/2.0 
     let containsStacks = dataSet.isStacked 
     let isInverted = dataProvider.isInverted(dataSet.axisDependency) 
     var entries = dataSet.yVals as! [BarChartDataEntry] 
     let barWidth: CGFloat = 0.5 
     let phaseY = _animator.phaseY 
     var barRect = CGRect() 
     var barShadow = CGRect() 
     var y: Double 

     // do the drawing 
     for (var j = 0, count = Int(ceil(CGFloat(dataSet.entryCount) * _animator.phaseX)); j < count; j++) 
     { 
      let e = entries[j] 

      // calculate the x-position, depending on datasetcount 
      let x = CGFloat(e.xIndex + e.xIndex * dataSetOffset) + CGFloat(index) 
       + groupSpace * CGFloat(e.xIndex) + groupSpaceHalf 
      var vals = e.values 

      if (!containsStacks || vals == nil) 
      { 
       y = e.value 

       let left = x - barWidth + barSpaceHalf 
       let right = x + barWidth - barSpaceHalf 
       var top = isInverted ? (y <= 0.0 ? CGFloat(y) : 0) : (y >= 0.0 ? CGFloat(y) : 0) 
       var bottom = isInverted ? (y >= 0.0 ? CGFloat(y) : 0) : (y <= 0.0 ? CGFloat(y) : 0) 

       // multiply the height of the rect with the phase 
       if (top > 0) 
       { 
        top *= phaseY 
       } 
       else 
       { 
        bottom *= phaseY 
       } 

       barRect.origin.x = left 
       barRect.size.width = right - left 
       barRect.origin.y = top 
       barRect.size.height = bottom - top 

       trans.rectValueToPixel(&barRect) 

       if (!viewPortHandler.isInBoundsLeft(barRect.origin.x + barRect.size.width)) 
       { 
        continue 
       } 

       if (!viewPortHandler.isInBoundsRight(barRect.origin.x)) 
       { 
        break 
       } 

       // if drawing the bar shadow is enabled 
       if (drawBarShadowEnabled) 
       { 
        barShadow.origin.x = barRect.origin.x 
        barShadow.origin.y = viewPortHandler.contentTop 
        barShadow.size.width = barRect.size.width 
        barShadow.size.height = viewPortHandler.contentHeight 

        CGContextSetFillColorWithColor(context, dataSet.barShadowColor.CGColor) 
        CGContextFillRect(context, barShadow) 
       } 

       // Set the color for the currently drawn value. If the index is out of bounds, reuse colors. 

       let lbl = UILabel() 
       lbl.drawTextInRect(barRect) 

       CGContextSetFillColorWithColor(context, dataSet.colorAt(j).CGColor) 
       CGContextFillRect(context, barRect) 
      } 
      else 
      { 
       var posY = 0.0 
       var negY = -e.negativeSum 
       var yStart = 0.0 

       // if drawing the bar shadow is enabled 
       if (drawBarShadowEnabled) 
       { 
        y = e.value 

        let left = x - barWidth + barSpaceHalf 
        let right = x + barWidth - barSpaceHalf 
        var top = isInverted ? (y <= 0.0 ? CGFloat(y) : 0) : (y >= 0.0 ? CGFloat(y) : 0) 
        var bottom = isInverted ? (y >= 0.0 ? CGFloat(y) : 0) : (y <= 0.0 ? CGFloat(y) : 0) 

        // multiply the height of the rect with the phase 
        if (top > 0) 
        { 
         top *= phaseY 
        } 
        else 
        { 
         bottom *= phaseY 
        } 

        barRect.origin.x = left 
        barRect.size.width = right - left 
        barRect.origin.y = top 
        barRect.size.height = bottom - top 

        trans.rectValueToPixel(&barRect) 

        barShadow.origin.x = barRect.origin.x 
        barShadow.origin.y = viewPortHandler.contentTop 
        barShadow.size.width = barRect.size.width 
        barShadow.size.height = viewPortHandler.contentHeight 

        CGContextSetFillColorWithColor(context, dataSet.barShadowColor.CGColor) 
        CGContextFillRect(context, barShadow) 
       } 

       // fill the stack 
       for (var k = 0; k < vals!.count; k++) 
       { 
        let value = vals![k] 

        if value >= 0.0 
        { 
         y = posY 
         yStart = posY + value 
         posY = yStart 
        } 
        else 
        { 
         y = negY 
         yStart = negY + abs(value) 
         negY += abs(value) 
        } 

        let left = x - barWidth + barSpaceHalf 
        let right = x + barWidth - barSpaceHalf 
        var top: CGFloat, bottom: CGFloat 
        if isInverted 
        { 
         bottom = y >= yStart ? CGFloat(y) : CGFloat(yStart) 
         top = y <= yStart ? CGFloat(y) : CGFloat(yStart) 
        } 
        else 
        { 
         top = y >= yStart ? CGFloat(y) : CGFloat(yStart) 
         bottom = y <= yStart ? CGFloat(y) : CGFloat(yStart) 
        } 

        // multiply the height of the rect with the phase 
        top *= phaseY 
        bottom *= phaseY 

        barRect.origin.x = left 
        barRect.size.width = right - left 
        barRect.origin.y = top 
        barRect.size.height = bottom - top 

        trans.rectValueToPixel(&barRect) 

        if (k == 0 && !viewPortHandler.isInBoundsLeft(barRect.origin.x + barRect.size.width)) 
        { 
         // Skip to next bar 
         break 
        } 

        // avoid drawing outofbounds values 
        if (!viewPortHandler.isInBoundsRight(barRect.origin.x)) 
        { 
         break 
        } 

        // Set the color for the currently drawn value. If the index is out of bounds, reuse colors. 
        CGContextSetFillColorWithColor(context, dataSet.colorAt(k).CGColor) 
        CGContextFillRect(context, barRect) 
       } 
      } 
      // Define your label code here 
      let lbl = UILabel() 
      lbl.text = "\(e.values)" 
      lbl.drawTextInRect(barRect) 
     } 


     CGContextRestoreGState(context) 
    } 

コードについてはわかりませんが、ここで何かする必要があります。遅くなったら私の答えに何か変更が必要です。

ハッピーコーディング...

関連する問題