Charts: BarChart xAxis ๋ ˆ์ด๋ธ” ์˜คํ”„์…‹

์— ๋งŒ๋“  2016๋…„ 11์›” 23์ผ  ยท  4์ฝ”๋ฉ˜ํŠธ  ยท  ์ถœ์ฒ˜: danielgindi/Charts

๋‹ค์‹œ ํ•œ ๋ฒˆ ์•ˆ๋…•ํ•˜์„ธ์š”. ๋จผ์ € ์ง€๋‚œ ํ˜ธ์— ์ด๋ ‡๊ฒŒ ๋นจ๋ฆฌ ์‘๋‹ตํ•ด ์ฃผ์…”์„œ ๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค. ๊ทธ๋ž˜๋„ ๋‹ค๋ฅธ ์งˆ๋ฌธ์ด ์žˆ์Šต๋‹ˆ๋‹ค. ํ•˜๋‹จ์— ๋ ˆ์ด๋ธ”์ด ์žˆ๋Š” ๋ง‰๋Œ€ ์ฐจํŠธ๋ฅผ ์ƒ์„ฑํ•  ๋•Œ ์ฒซ ๋ฒˆ์งธ ๋ ˆ์ด๋ธ”์€ ๊ฐ ๋ง‰๋Œ€ ๋ฐ”๋กœ ์•„๋ž˜๊ฐ€ ์•„๋‹ˆ๋ผ ์˜คํ”„์…‹๋ฉ๋‹ˆ๋‹ค.
screen shot 2016-11-22 at 3 25 27 pm ๋ฐ๋ชจ๋ฅผ ์‚ดํŽด๋ณด๊ณ  ๊ทธ์— ๋”ฐ๋ผ ๋ชจ๋“  ์„ค์ •์„ ์ผ์น˜์‹œ์ผฐ์Šต๋‹ˆ๋‹ค. chartView.isUserInteractionEnabled = false chartView.chartDescription?.text = "" chartView.drawBarShadowEnabled = false chartView.rightAxis.drawGridLinesEnabled = false chartView.rightAxis.drawAxisLineEnabled = false chartView.rightAxis.drawLabelsEnabled = false chartView.xAxis.avoidFirstLastClippingEnabled = true chartView.xAxis.centerAxisLabelsEnabled = false chartView.xAxis.drawLimitLinesBehindDataEnabled = false chartView.xAxis.labelPosition = .bottom chartView.xAxis.labelCount = 3 chartView.xAxis.axisMinimum = -0.5 chartView.xAxis.axisMaximum = 3 chartView.xAxis.drawGridLinesEnabled = false chartView.fitBars = true chartView.xAxis.granularity = 1 ๋‹ค๋ฅธ ์†์„ฑ์„ ์‹œ๋„ํ• ์ง€ ์ž˜ ๋ชจ๋ฅด๊ฒ ์Šต๋‹ˆ๋‹ค. ์•ˆ๋‚ดํ•ด ์ฃผ์‹œ๋ฉด ๊ฐ์‚ฌํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค. ๋‹ค์‹œ ํ•œ๋ฒˆ ๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค

๋ชจ๋“  4 ๋Œ“๊ธ€

๋‹ค์Œ์€ ๊ทธ๋ž˜ํ”„๋ฅผ ์„ค์ •ํ•˜๊ธฐ ์œ„ํ•ด ํ˜ธ์ถœํ•œ ์ „์ฒด ํ•จ์ˆ˜์ž…๋‹ˆ๋‹ค. `func setUpChart(delegate: IAxisValueFormatter){

    var dataEntries = [BarChartDataEntry]()
    var barChartDataSet = BarChartDataSet()

    for i in 0..<items.count {
        let de = BarChartDataEntry(x: Double(i), yValues: [itemsValues[i]])
        dataEntries.append(de)
    }


    barChartDataSet = BarChartDataSet(values: dataEntries , label: "Monthly Income")

    chartView.isUserInteractionEnabled = false
    chartView.chartDescription?.text = ""
    chartView.drawBarShadowEnabled = false
    chartView.rightAxis.drawGridLinesEnabled = false
    chartView.rightAxis.drawAxisLineEnabled = false
    chartView.rightAxis.drawLabelsEnabled = false
    chartView.xAxis.avoidFirstLastClippingEnabled = true
    chartView.xAxis.centerAxisLabelsEnabled = false
    chartView.xAxis.drawLimitLinesBehindDataEnabled = false
    chartView.xAxis.labelPosition = .bottom
    chartView.xAxis.labelCount = 3
    chartView.xAxis.axisMinimum = -0.5
    chartView.xAxis.axisMaximum = 3
    chartView.xAxis.drawGridLinesEnabled = false
    chartView.fitBars = true
    chartView.xAxis.granularity = 1
    chartView.xAxis.valueFormatter = delegate


    barChartDataSet.colors = ChartColorTemplates.colorful()


    self.chartView.animate(xAxisDuration: 1.5, yAxisDuration: 1.5, easingOption: .easeInOutCirc)

    let bcData = BarChartData(dataSet: barChartDataSet)

    bcData.barWidth = 0.5
    self.chartView.data = bcData


}`

avoidFirstLastClippingEnabled ๋น„ํ™œ์„ฑํ™” ํ™œ์„ฑํ™”ํ•˜๋ฉด ํšจ๊ณผ๊ฐ€ ์žˆ์Šต๋‹ˆ๋‹ค. ๋ฒ„๊ทธ์ฒ˜๋Ÿผ ๋ณด์ž…๋‹ˆ๋‹ค.

๊บพ์€์„ ํ˜• ์ฐจํŠธ์—์„œ ๋น„์Šทํ•œ ๋ฌธ์ œ๊ฐ€ ๋ฐœ์ƒํ•˜์—ฌ xAxis์˜ ์ฒซ ๋ฒˆ์งธ ๋ ˆ์ด๋ธ”์ด ๊บผ์ ธ ์žˆ์Šต๋‹ˆ๋‹ค.

screen shot 2016-11-29 at 3 28 53 pm

์ด ๋ฌธ์ œ๋ฅผ ํ•ด๊ฒฐํ•˜๊ธฐ ์œ„ํ•ด ์ฐพ์€ ์œ ์ผํ•œ ๋ฐฉ๋ฒ•์€ xAxis.centerAxisLabelsEnabled = true ๊ฒƒ์ด์ง€๋งŒ ๊ฐ•์กฐ ํ‘œ์‹œ๊ฐ€ ํ•ด์ œ๋  ๊ฒƒ์ž…๋‹ˆ๋‹ค.

์—ฌ๊ธฐ ๋‚ด xAxis ์ฝ”๋“œ๊ฐ€ ์žˆ์Šต๋‹ˆ๋‹ค. ์–ด๋–ค ๋„์›€์ด๋“  ํ™˜์˜ํ•ฉ๋‹ˆ๋‹ค.

 func setupXAxisFormatting() {
        let xAxis = lineChartView.xAxis
        xAxis.enabled = true
        xAxis.drawGridLinesEnabled = false
        xAxis.drawLabelsEnabled = true
        xAxis.drawAxisLineEnabled = false
        xAxis.centerAxisLabelsEnabled = true //would rather fix another way

        xAxis.labelPosition = .bottom
        xAxis.labelTextColor = UIColor.gray
        xAxis.labelFont = UIFont(name: Constants.Fonts.ProximaNovaBold, size: 15.0)!

        xAxis.avoidFirstLastClippingEnabled = true
        xAxis.spaceMin = 5
        xAxis.valueFormatter = axisFormatDelegate
    }

@Rnorback "xAxis ์˜ ์ฒซ ๋ฒˆ์งธ ๋ ˆ์ด๋ธ”์ด ๊บผ์ ธ ์žˆ์Šต๋‹ˆ๋‹ค"์™€ ๊ฐ™์€ ๋ฌธ์ œ๊ฐ€ ์•„๋‹ˆ๋ผ๊ณ  ์ƒ๊ฐํ•ฉ๋‹ˆ๊นŒ? 'offeFirstLastClippingEnabled'๋ฅผ ๋„๋ฉด '11/23'์„ ์™ผ์ชฝ์œผ๋กœ ์•ฝ๊ฐ„์˜ ๊ณต๊ฐ„๋งŒํผ ์ด๋™ํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.

์ด ํŽ˜์ด์ง€๊ฐ€ ๋„์›€์ด ๋˜์—ˆ๋‚˜์š”?
0 / 5 - 0 ๋“ฑ๊ธ‰