Charts: LineChart X μΆ•-항상 첫 번째 및 λ§ˆμ§€λ§‰ λ ˆμ΄λΈ”μ„ ν‘œμ‹œν•˜λŠ” 방법

에 λ§Œλ“  2016λ…„ 12μ›” 26일  Β·  21μ½”λ©˜νŠΈ  Β·  좜처: danielgindi/Charts

λ‚΄ 꺾은 μ„ ν˜• μ°¨νŠΈμ—μ„œ 데이터 ν•­λͺ©μ΄ ν•˜λ‚˜λ§ŒμžˆλŠ” 경우 데이터 ν¬μΈνŠΈκ°€ λ‹€μŒκ³Ό 같이 쀑간에 ν‘œμ‹œλ˜λ„λ‘ μ„€μ •ν–ˆμŠ΅λ‹ˆλ‹€.

screen shot 2016-12-25 at 7 00 36 pm

더 λ§Žμ€ 데이터 ν•­λͺ©μ΄ 있으면 λ‹€μŒκ³Ό 같이 ν‘œμ‹œλ©λ‹ˆλ‹€.

screen shot 2016-12-25 at 7 00 50 pm

λ‚΄κ°€ 가진 λ¬Έμ œλŠ” X μΆ•μ˜ λ§ˆμ§€λ§‰ λ ˆμ΄λΈ”μ΄ ν‘œμ‹œλ˜μ§€ μ•ŠλŠ”λ‹€λŠ” κ²ƒμž…λ‹ˆλ‹€. 이것은 μ§€λ‚œ 30 일 λ™μ•ˆμ˜ λ°μ΄ν„°μ΄λ―€λ‘œ λ§ˆμ§€λ§‰ λ ˆμ΄λΈ” 인 12 μ›” 25 일을 ν‘œμ‹œν•˜κ³  μ‹ΆμŠ΅λ‹ˆλ‹€. λ‚΄ 꺾은 μ„ ν˜• μ°¨νŠΈκ°€ 항상 X μΆ•μ˜ 첫 λ²ˆμ§Έμ™€ λ§ˆμ§€λ§‰ λ ˆμ΄λΈ”μ„ ν‘œμ‹œν•˜λ„λ‘ν•˜λŠ” 방법이 μžˆμŠ΅λ‹ˆκΉŒ? 사이에 λ ˆμ΄λΈ”μ„ κ³„μ‚°ν•˜κ±°λ‚˜ κ±΄λ„ˆ λ›°λŠ” 방법은 상관 μ—†μŠ΅λ‹ˆλ‹€.

κ°€μž₯ μœ μš©ν•œ λŒ“κΈ€

    lineChart?.xAxis.setLabelCount(arrOfMonth.count, force: true)

이것은 라인 차트의 λ§ˆμ§€λ§‰ 값을 ν‘œμ‹œν•˜λŠ” 데 도움이 될 κ²ƒμž…λ‹ˆλ‹€.

λͺ¨λ“  21 λŒ“κΈ€

avoidFirstLastClippingEnabled μ‹œλ„, 기본값은 falseμž…λ‹ˆλ‹€.

    /// if set to true, the chart will avoid that the first and last label entry in the chart "clip" off the edge of the chart
    open var avoidFirstLastClippingEnabled = false

@ cnowak7 두 번째 이미지에 μ–ΈκΈ‰ 된 문제λ₯Ό ν•΄κ²°ν•  수 μžˆμ—ˆμŠ΅λ‹ˆκΉŒ? μ†”λ£¨μ…˜μ„ κ³΅μœ ν•˜μ‹­μ‹œμ˜€

avoidFirstLastClippingEnabled 은 λ„μ›€μ΄λ˜μ§€ μ•ŠμŠ΅λ‹ˆλ‹€. λ§ˆμ§€λ§‰ λ ˆμ΄λΈ”μ€ 항상 μž˜λ¦½λ‹ˆλ‹€.

μ†ŒμŠ€ μ½”λ“œλ₯Ό μ‚΄νŽ΄λ³΄λ©΄ μΆ• ν•­λͺ©μ΄ AxisRendererBase.computeAxisValues 둜 κ³„μ‚°λ˜λ©° μ΅œλŒ€ 값을 ν‘œμ‹œν•˜λ„λ‘ κ°•μ œ ν•  방법이 μ—†μŠ΅λ‹ˆλ‹€. 이 κΈ°λŠ₯은 이전 λ²„μ „μ—μ„œ μ§€μ›λ˜μ—ˆλ‹€κ³  μƒκ°ν•©λ‹ˆλ‹€.

https://github.com/danielgindi/Charts/issues/2007이 이것과 같은 문제둜 λ³΄μž…λ‹ˆκΉŒ?
@ondrejhanslik 기본적으둜 computeAxisValues ​​()λŠ” λ²”μœ„λ₯Ό κ³„μ‚°ν•˜κΈ° μœ„ν•΄ μ΅œμ†Œκ°’κ³Ό μ΅œλŒ€ 값을 μ‚¬μš©ν•©λ‹ˆλ‹€. λ”°λΌμ„œ λͺ¨λ“  데이터λ₯Ό λ³΄κ΄€ν•˜λ €λ©΄ μ΅œμ†Œκ°’κ³Ό μ΅œλŒ€ 값이 λ°μ΄ν„°μ˜ μ΅œμ†Œ / μ΅œλŒ€ 값보닀 μ»€μ•Όν•©λ‹ˆλ‹€. computeAxisValues ​​()μ—μ„œ μ΅œμ†Œ / μ΅œλŒ€ 값이 무엇이며 λ°μ΄ν„°μ˜ μ΅œμ†Œ / μ΅œλŒ€ 값이 무엇인지 확인 ν–ˆμŠ΅λ‹ˆκΉŒ?

@ liuxuan30 μ‚¬μš©μž 지정 λ¬Έμžμ—΄ 배열을 X μΆ• κ°’ 즉 λ‚ μ§œλ‘œ μ‚¬μš©ν•©λ‹ˆλ‹€.

λ‹€μŒμ€ λ‚΄ 차트의 슀크린 μƒ·μž…λ‹ˆλ‹€.

untitled

avoidFirstLastClippingEnabled λ₯Ό true둜 μ„€μ •ν•˜λ©΄ λ‚΄ μ°¨νŠΈκ°€ λ‹€μŒκ³Ό 같이 λ³΄μž…λ‹ˆλ‹€.

screen shot 2016-12-28 at 11 02 15 pm

λ‹€μŒμ€ X 좕을 μ„€μ •ν•˜λŠ” 데 μ‚¬μš©ν•˜λŠ” λͺ‡ 가지 μΆ”κ°€ μ½”λ“œμž…λ‹ˆλ‹€.

private func setUpLineChartPreferences() {
        .
        .
        .
        // x-axis
        self.lineChart.xAxis.labelPosition = .bottom
        self.lineChart.xAxis.drawGridLinesEnabled = true
        self.lineChart.xAxis.granularity = 1.0
        .
        .
        .
}
private func setUpLineChart(withDataEntries entries: [ChartDataEntry]) {
        let entryCount = entries.count
        if entryCount > 0 {
            let dataSet = LineChartDataSet(values: entries, label: nil)
            dataSet.drawFilledEnabled = true
            dataSet.fillColor = .green
            dataSet.circleRadius = 5
            dataSet.drawValuesEnabled = false
            dataSet.setColor(.black)
            dataSet.highlightColor = .green
            dataSet.setCircleColor(.blue)
            let lineChartData = LineChartData(dataSet: dataSet)
            self.lineChart.data = lineChartData
            // SET UP X-AXIS
            self.lineChart.xAxis.valueFormatter = IndexAxisValueFormatter(values: self.chartLabels)
            self.lineChart.xAxis.avoidFirstLastClippingEnabled = true
            print("NOWAK: CHART LABELS THO - \(self.chartLabels)")
            if entryCount == 1 {
                self.lineChart.xAxis.axisMinimum = -1.0
                self.lineChart.xAxis.axisMaximum = 1.0
            } else {
                self.lineChart.xAxis.axisMinimum = 0.0
                self.lineChart.xAxis.axisMaximum = Double(self.chartLabels.count - 1)
            }
            print("X MIN IS \(self.lineChart.xAxis.axisMinimum) AND X MAX IS \(self.lineChart.xAxis.axisMaximum)")
        } else {
            self.lineChart.noDataText = "No Stats For The Past \(self.currentFilter.capitalized)"
            self.lineChart.setNeedsDisplay()
        }
        switch self.currentFilter {
        case "week":
            self.weekFilterButton.backgroundColor = .blue
            self.monthFilterButton.backgroundColor = .darkGray
            self.yearFilterButton.backgroundColor = .darkGray
        case "month":
            self.monthFilterButton.backgroundColor = .blue
            self.weekFilterButton.backgroundColor = .darkGray
            self.yearFilterButton.backgroundColor = .darkGray
        case "year":
            self.yearFilterButton.backgroundColor = .blue
            self.weekFilterButton.backgroundColor = .darkGray
            self.monthFilterButton.backgroundColor = .darkGray
        default:
            print("ERROR SETTING FILTER BUTTON BACKGROUND COLORS")
        }
        self.stopLoading()
}

λ‚˜λŠ” Charts 3.0.1을 μ‚¬μš©ν•˜κ³  μžˆμŠ΅λ‹ˆλ‹€. :)

여기도 λ§ˆμ°¬κ°€μ§€μž…λ‹ˆλ‹€. Charts 3.0.1 , XCode 8.0 및 Swift 3.0

이 상황에 λŒ€ν•œ 해결책이 λΆˆκ°€λŠ₯ν•œ 경우, μ°¨νŠΈκ°€ ν‘œμ‹œ 될 λ•Œ λ§ˆμ§€λ§‰ κ°’ (였늘)을 κ°•μ‘° ν‘œμ‹œν•˜μ—¬ "BalloonMarker"에 "Dec XX \ n500 ".

λ‚΄ νŽΈμ— λΆ„λͺ…νžˆ :)

ν™•μΈν–ˆμŠ΅λ‹ˆλ‹€.

차트 3.0μ—μ„œ x 좕은 y μΆ•μ²˜λŸΌ λ™μž‘ν•˜λ―€λ‘œ y μΆ• λ ˆμ΄λΈ”μ„ 확인할 수 μžˆμŠ΅λ‹ˆλ‹€. κ°€μž₯ 큰 y μΆ• λ ˆμ΄λΈ”μ€ λ°μ΄ν„°μ˜ μ΅œλŒ€ 값보닀 μž‘μŠ΅λ‹ˆλ‹€.
image

computeAxisValues() μ—μ„œλŠ” μΆ•μ˜ μ΅œμ†Œ / μ΅œλŒ€ κ°’ (λ°μ΄ν„°μ˜ μ΅œμ†Œ / μ΅œλŒ€ κ°’)μ—μ„œ μ΅œμ†Œκ°’κ³Ό μ΅œλŒ€ 값을 읽고 x μΆ• λ ˆμ΄λΈ”μ„ μ–»κΈ°μœ„ν•œ 간격을 κ³„μ‚°ν•©λ‹ˆλ‹€.

예λ₯Ό λ“€μ–΄ ChartsDemo-Line Chart Dual YAxisμ—μ„œ x 값이 0μ—μ„œ 20 사이 인 경우
computeAxisValues() λŠ” μ΅œμ†Œ / μ΅œλŒ€ κ°’μœΌλ‘œ 0, 20을 μ·¨ν•˜κ³ , λ‚΄ labelCount λŠ” 기본적으둜 6이고, rawInterval = (max - min) / labelCount κ³„μ‚°ν•˜κ³  λ‚˜μ€‘μ— μ΅œμ’… 간격은 3μ΄λ©λ‹ˆλ‹€. 0λΆ€ν„° μ‹œμž‘ν•˜μ—¬ 0,3,6,9,12,15,18 인 7 (labelCount + 1) λ ˆμ΄λΈ”μ„ μ–»μŠ΅λ‹ˆλ‹€. λ§ˆμ§€λ§‰ x μΆ• λ ˆμ΄λΈ”μ€ 20이 μ•„λ‹ˆλΌ 18μž…λ‹ˆλ‹€.

isAvoidFirstLastClippingEnabled κ°€ μž‘λ™ν•˜μ§€ μ•ŠλŠ” μ΄μœ λŠ” λ§ˆμ§€λ§‰ λ ˆμ΄λΈ”μ΄ 경계λ₯Ό λ²—μ–΄ 났을 λ•Œ μ²˜λ¦¬ν•˜κΈ° λ•Œλ¬Έμ—μ΄ λ¬Έμ œμ™€ 관련이 μ—†μŠ΅λ‹ˆλ‹€.

λ°μ΄ν„°μ˜ x 값인 λ ˆμ΄λΈ”μ„ ν™•μΈν•˜λ €λ©΄ computeAxisValues() λ₯Ό μ‘°μ •ν•˜μ—¬ λ ˆμ΄λΈ”μ„ λ°˜ν™˜ν•΄μ•Όν•©λ‹ˆλ‹€. computeAxisValues() μ—μ„œ μžμ„Έν•œ λ‚΄μš©μ„ ν™•μΈν•˜λ©΄ λ³€κ²½ν•  수 μžˆμŠ΅λ‹ˆλ‹€.

@danielgindi 그런 μ‚¬μš©μž 사둀에 λŒ€ν•΄ μ–΄λ–»κ²Œ μƒκ°ν•˜μ‹­λ‹ˆκΉŒ?

@ liuxuan30 νŠΉμ • λ ˆμ΄λΈ”μ„ λ°˜ν™˜ν•˜κΈ° μœ„ν•΄ computeAxisValues 을 μ‘°μ •ν•˜κ³  싢지 μ•ŠμŠ΅λ‹ˆλ‹€. 예λ₯Ό λ“€μ–΄, λ‚ μ§œλ³„λ‘œ 차트λ₯Ό ν‘œμ‹œ ν•  λ•Œ (예 : x- 값은 μš”μΌ, ν•œ λ‹¬μ˜ 일 λ˜λŠ” 1 λ…„μ˜ 달) ν‘œμ‹œ ν•  첫 번째 및 λ§ˆμ§€λ§‰ λ ˆμ΄λΈ” (예 : μ›”μš”μΌκ³Ό μΌμš”μΌ λ˜λŠ” 1 / 1 및 31/1).

λ¨Όμ € ν˜•μ‹μ΄ μ§€μ •λœ κ°’ (예 : μš”μΌ 이름 λ˜λŠ” ν˜•μ‹μ΄ μ§€μ •λœ μš”μΌ)을 생성 ν•œ λ‹€μŒ λ‹€μŒκ³Ό 같이 μ„€μ •ν•©λ‹ˆλ‹€.

    xAxis.axisMinimum = 0
    xAxis.axisMaximum = Double(xValues.count - 1)
    xAxis.valueFormatter = IndexAxisValueFormatter(values: xValues)

λ‚΄κ°€ ν•„μš”ν•œ 것은 항상 첫 번째 λ ˆμ΄λΈ”κ³Ό λ§ˆμ§€λ§‰ λ ˆμ΄λΈ”μ„ ν‘œμ‹œ ν•œ λ‹€μŒ λ‘˜ μ‚¬μ΄μ˜ λ ˆμ΄λΈ”μ„ κ³„μ‚°ν•˜λŠ” 더 λ˜‘λ˜‘ν•œ computeAxisValues μž…λ‹ˆλ‹€.

이것은 맀우 기본적이고 맀우 일반적인 μ‚¬μš© μ‚¬λ‘€μž…λ‹ˆλ‹€.

이해 ν–ˆμ–΄μš”. x μΆ• λ ˆμ΄λΈ”μ— λŒ€ν•œ 버그가 μžˆμŠ΅λ‹ˆλ‹€ (예 : λ ˆμ΄λΈ” κ²ΉμΉ¨).
ν˜„μž¬ λ‘œμ§μ€ λ¨Όμ € μ΅œμ†Œ / μ΅œλŒ€ 값을 μ•Œκ³ , κ·Έλ‘œλΆ€ν„° 간격을 μƒμ„±ν•˜κ³  λˆ„μ ν•˜μ—¬ μΆ• λ ˆμ΄λΈ”μ„ μ–»μŠ΅λ‹ˆλ‹€. κ·ΈλŸ¬λ‚˜ ν˜„μž¬ computeAxisValues() 은 μ΅œλŒ€ κ°’ / λ§ˆμ§€λ§‰ λ ˆμ΄λΈ”μ΄ xAxis.axisMaximumμž„μ„ 보μž₯ν•˜μ§€ μ•ŠμŠ΅λ‹ˆλ‹€. 그것이 λ‚΄κ°€ 이것에 λŒ€ν•΄ @danielgindi 의 μž…λ ₯이 ν•„μš”ν•œ κ²ƒμž…λ‹ˆλ‹€.

computeAxisValues ​​()에 'tweak'λ³΄λ‹€λŠ” 'override'λ₯Ό μ‚¬μš©ν•΄μ•Ό ν•  μˆ˜λ„ μžˆμŠ΅λ‹ˆλ‹€. 첫 번째 / λ§ˆμ§€λ§‰ 값이 항상 ν•΄κ²° λ°©λ²•μœΌλ‘œ ν‘œμ‹œλ˜λ„λ‘ κ΅¬ν˜„μ„ 제곡 ν•  수 μžˆμŠ΅λ‹ˆλ‹€. κ·ΈλŸ¬λ‚˜ 이둜 인해 λ ˆμ΄λΈ”μ΄ 경계λ₯Ό λ²—μ–΄ λ‚¬κ±°λ‚˜ λ‹€λ₯Έ λ¬Έμ œκ°€ λ°œμƒν•  수 μžˆμŠ΅λ‹ˆλ‹€.

또 λ‹€λ₯Έ 방법은 setLabelCount(count, forceLabelEnabled) 이 x κ°’ κ°œμˆ˜μ™€ κ°™κ±°λ‚˜ κ²°κ³Όλ₯Ό ν™•μΈν•˜κΈ° μœ„ν•΄ μ ˆλ°˜μ„ μ‹œλ„ν•˜λŠ” κ²ƒμž…λ‹ˆλ‹€.
λ…Όλ¦¬λŠ” μƒλ‹Ήνžˆ λ‹€λ¦…λ‹ˆλ‹€.

        // force label count
        if axis.isForceLabelsEnabled
        {
            interval = Double(range) / Double(labelCount - 1)

            // Ensure stops contains at least n elements.
            axis.entries.removeAll(keepingCapacity: true)
            axis.entries.reserveCapacity(labelCount)

            var v = yMin

            for _ in 0 ..< labelCount
            {
                axis.entries.append(v)
                v += interval
            }

            n = labelCount
        }

μΆ”κ°€ 과정이 μ•„λ‹ˆλΌ λ‹¨μˆœν•œ μˆ˜ν•™λΏμž…λ‹ˆλ‹€.

@ liuxuan30 x μΆ• 값이 λ¬Έμžμ—΄ ν˜•μ‹

@ vaibhav-varshaaweblabs x 좕은 이제 차트 3.xμ—μ„œ 두 배만 μ‚¬μš©ν•˜λ―€λ‘œ valueFormatterλ₯Ό μ‚¬μš©ν•˜μ—¬ 두 λ°° λŒ€μ‹  λ ˆμ΄λΈ”μ„ ν‘œμ‹œ ν•  수 μžˆμŠ΅λ‹ˆλ‹€. κ·ΈλŸ¬λ‚˜ ν™•λŒ€ / μΆ•μ†Œ / μŠ€ν¬λ‘€μ„ κ³ λ €ν•΄μ•Όν•˜λŠ” 경우 valueFormatterκ°€ 볡작 ν•  수 μžˆμŠ΅λ‹ˆλ‹€.

λˆ„κ΅¬λ“ μ§€ Charts 3.0.2μ—μ„œ 이에 λŒ€ν•œ 해결책을 μ°Ύμ•˜μŠ΅λ‹ˆκΉŒ? x μΆ• λ ˆμ΄λΈ”μ— λ‚ μ§œ λ¬Έμžμ—΄μ„ μ‚¬μš©ν•˜κ³  있으며 λ§ˆμ§€λ§‰ λ ˆμ΄λΈ”μ΄ 가끔 μ‚¬λΌμ§€λŠ” 것을 λ³΄μ•˜μ§€λ§Œ μž¬ν˜„ν•˜λŠ” 데 λ¬Έμ œκ°€ μžˆμŠ΅λ‹ˆλ‹€. isAvoidFirstLastClippingEnabled 이 true μ„€μ •λ˜μ–΄ μžˆμŠ΅λ‹ˆλ‹€. 이것이 # 2563κ³Ό 관련이 μžˆλŠ”μ§€ κΆκΈˆν•©λ‹ˆλ‹€.

@ vaibhav-varshaaweblabs @raudabaugh : setDataCount λ©”μ„œλ“œκ°€ X 및 Y에 λŒ€ν•΄ int λ˜λŠ” double 값을 μ˜ˆμƒν•˜κΈ° λ•Œλ¬Έμ— μ–΄λ–»κ²Œ μ‚¬μš©μžκ°€ X 좕에 λ¬Έμžμ—΄μ„ 그릴 수 μžˆμ—ˆμŠ΅λ‹ˆκΉŒ?
μΉœμ ˆν•˜κ²Œ μ•Œλ €μ£Όμ„Έμš”. 미리 κ°μ‚¬λ“œλ¦½λ‹ˆλ‹€.

bottomAxis.setLabelCount (entries.size (), true); λ§ˆμ§€λ§‰μœΌλ‘œ ν‘œμ‹œλ˜λ„λ‘ 여백을 였λ₯Έμͺ½μœΌλ‘œ μ„€μ •ν•©λ‹ˆλ‹€.

    lineChart?.xAxis.setLabelCount(arrOfMonth.count, force: true)

이것은 라인 차트의 λ§ˆμ§€λ§‰ 값을 ν‘œμ‹œν•˜λŠ” 데 도움이 될 κ²ƒμž…λ‹ˆλ‹€.

이 νŽ˜μ΄μ§€κ°€ 도움이 λ˜μ—ˆλ‚˜μš”?
0 / 5 - 0 λ“±κΈ‰

κ΄€λ ¨ 문제

newbiebie picture newbiebie  Β·  3μ½”λ©˜νŠΈ

cilasgimenez picture cilasgimenez  Β·  4μ½”λ©˜νŠΈ

Aungbandlab picture Aungbandlab  Β·  4μ½”λ©˜νŠΈ

valeIT picture valeIT  Β·  3μ½”λ©˜νŠΈ

brytnvmg picture brytnvmg  Β·  4μ½”λ©˜νŠΈ