Charts: λ§‰λŒ€ 차트λ₯Ό ν‘œμ‹œν•˜μ§€ μ•ŠλŠ” λ§‰λŒ€

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

μ•ˆλ…•ν•˜μ„Έμš”,

3.0으둜 μ—…κ·Έλ ˆμ΄λ“œ ν•œ ν›„ λ§‰λŒ€ μ°¨νŠΈμ— λ§‰λŒ€κ°€ ν‘œμ‹œλ˜μ§€ μ•ŠλŠ” λ¬Έμ œκ°€ μžˆμŠ΅λ‹ˆλ‹€.

ν•˜λ‚˜μ˜ λ§‰λŒ€λŠ” 데이터에 ν¬μΈνŠΈκ°€ ν•˜λ‚˜λ§ŒμžˆλŠ” 경우λ₯Ό ν‘œμ‹œν•©λ‹ˆλ‹€. 점을 두 개 이상 μΆ”κ°€ν•˜λ©΄ λ§‰λŒ€κ°€ ν‘œμ‹œλ˜μ§€ μ•ŠμŠ΅λ‹ˆλ‹€.
이것은 xaxis에 λ‚ μ§œκ°€μžˆμ„ λ•Œλ§Œ λ°œμƒν•©λ‹ˆλ‹€. 데이터λ₯Ό λ‚ μ§œμ—μ„œ μ •μˆ˜λ‘œ λ³€κ²½ν•˜λ©΄ μ œλŒ€λ‘œ μž‘λ™ν•©λ‹ˆλ‹€.
첨뢀 된 슀크린 샷을 μ°Έμ‘°ν•˜μ‹­μ‹œμ˜€.

데이터 μƒ˜ν”Œμ€ λ‹€μŒκ³Ό μœ μ‚¬ν•©λ‹ˆλ‹€.
{
"09/04/2012": "245",
"02/05/2013": "227",
"04/07/2013 ':"234 ",
"07/08/2015": "244",
"2016 λ…„ 10 μ›” 11 일": "2254"
}

감사,
λ‹¨λ°œ

1

μ•„λž˜μ—μ„œ λ³Ό 수 μžˆλ“―μ΄ λ§‰λŒ€κ°€ μ „ν˜€ 보이지 μ•ŠμŠ΅λ‹ˆκΉŒ? 이 원인은 λ¬΄μ—‡μž…λ‹ˆκΉŒ?
2

bug discussion enhancement β˜…β˜…β˜…

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

이것이 λˆ„κ΅¬μ—κ²Œλ„ λ„μ›€μ΄λ˜λŠ”μ§€ ν™•μ‹€ν•˜μ§€ μ•Šμ§€λ§Œ λ™μΌν•œ λ¬Έμ œκ°€ μžˆμ—ˆκ³  x μΆ• λ²”μœ„μ— λŒ€ν•΄ μ˜¬λ°”λ₯Έ 크기둜 λ§‰λŒ€λ₯Ό μ„€μ •ν•˜μ—¬ ν•΄κ²°ν–ˆμŠ΅λ‹ˆλ‹€.

let data = BarChartData(dataSets: [dataSet])

let dataSetRange = dataSet.xMax - dataSet.xMin
let availableSpacePerBar = dataSetRange / Double(dataSet.entryCount)
data.barWidth = availableSpacePerBar * 0.8 // 80% of available space

chartView.data = data

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

λˆ„κ΅¬λ“ μ§€ 이것에 λŒ€ν•œ 해결책이 μžˆμŠ΅λ‹ˆκΉŒ?
3.0μ—μ„œ λ§‰λŒ€κ°€ λˆ„λ½ 된 것이 이상해 λ³΄μž…λ‹ˆλ‹€. λ‚΄κ°€ μ „ν™”λ₯Ό λ†“μΉ˜κ±°λ‚˜ 무언가λ₯Ό μ„€μ •ν•˜λŠ” 것 κ°™μŠ΅λ‹ˆλ‹€. 이에 λŒ€ν•œ 해결책이 μžˆλ‹€λ©΄ 맀우 도움이 될 κ²ƒμž…λ‹ˆλ‹€.

감사,
λ‹¨λ°œ

μ–΄λ–»κ²Œ μ„€μ •ν•©λ‹ˆκΉŒ? 차트 3.0은 x 좕을 재 μ„€κ³„ν–ˆκΈ° λ•Œλ¬Έμ— λ§Žμ€ 것이 λ³€κ²½λ˜μ—ˆμŠ΅λ‹ˆλ‹€. μ½”λ“œλ₯Ό μ—…λ°μ΄νŠΈν•˜μ§€ μ•ŠμœΌλ©΄ λˆ„λ½λ˜μ—ˆμ„ 수 μžˆμŠ΅λ‹ˆλ‹€. μ§€κΈˆμ€ ChartsDemoμ—μ„œ λ‹€λ₯Έ λ§‰λŒ€ 차트 데λͺ¨λ₯Ό ν™•μΈν•˜μ‹­μ‹œμ˜€.

데λͺ¨ 차트λ₯Ό λ‹€μ‹œ μ‹€ν–‰ν•˜μ—¬ 문제λ₯Ό μž¬ν˜„ ν•  수 μžˆλŠ”μ§€ ν™•μΈν•˜μ§€λ§Œ λ¬Έμ œκ°€ μ—΄λ¦° λ‹€λ₯Έ 문제 # 1716κ³Ό λΉ„μŠ·ν•˜λ‹€κ³  μƒκ°ν•©λ‹ˆλ‹€.

λ³€κ²½ 사항을 μ μš©ν•˜κ³  차트 데λͺ¨λ₯Ό μ‹€ν–‰ν•˜λ©΄ λ‹€μ‹œ 연락 λ“œλ¦¬κ² μŠ΅λ‹ˆλ‹€.

νŠΉμ • x 값이 문제λ₯Ό μΌμœΌν‚€λŠ” 것 κ°™μŠ΅λ‹ˆλ‹€.

감사,
λ‹¨λ°œ

λ‚˜λŠ” 같은 λ¬Έμ œκ°€ μžˆμŠ΅λ‹ˆλ‹€. λ‚΄ X 좕은 λ‚ μ§œλ₯Ό YYYY-MM-DD ν˜•μ‹μœΌλ‘œ μ˜¬λ°”λ₯΄κ²Œ ν‘œμ‹œν•˜μ§€λ§Œ λ§‰λŒ€λŠ” 보이지 μ•ŠμŠ΅λ‹ˆλ‹€.

@ liuxuan30 ,
μ—¬κΈ° λ‚΄κ°€ 기본적으둜 μ‹œλ„ν•œ κ²ƒμž…λ‹ˆλ‹€ ... 3.0μ—μ„œ ChartsDemoλ₯Ό μ•½κ°„ λ³€κ²½ν–ˆμœΌλ©° μ •ν™•νžˆ λ˜‘κ°™μ€ μΌμ„ν•˜κ³  μžˆμŠ΅λ‹ˆλ‹€ ...

λ‹€μŒκ³Ό 같이 λ³€κ²½ν–ˆμŠ΅λ‹ˆλ‹€. X 값이 두 배인 λŒ€μ‹  1970 λ…„ 이후 λ‚ μ§œμ˜ 두 λ°° 값인 datetime을 μΆ”κ°€ν•©λ‹ˆλ‹€.
xaxis 포맷터λ₯Ό dd / MM으둜 λ³€κ²½ν–ˆμŠ΅λ‹ˆλ‹€.

λ˜ν•œ BarChartViewController.m에 λŒ€ν•œ μ½”λ“œλ₯Ό μ²¨λΆ€ν•˜μ—¬ 확인할 수 μžˆμŠ΅λ‹ˆλ‹€.

μ•„λž˜ 슀크린 샷을 μ°Έμ‘°ν•˜μ‹­μ‹œμ˜€.
simulator screen shot nov 1 2016 12 22 47 am

BarChartViewController.m.zip

맀우 κ°„λ‹¨ν•œ 것을 λ†“μΉ˜κ³  μžˆκ±°λ‚˜ 이것은 λ²„κ·Έμž…λ‹ˆλ‹€.

감사,
λ‹¨λ°œ

μ•ˆλ…•ν•˜μ„Έμš”,이 λ¬Έμ œκ°€ μ™œ μ’…κ²°λ˜μ—ˆλŠ”μ§€ 잘 λͺ¨λ₯΄κ² μ§€λ§Œ 여기와 https://github.com/danielgindi/Charts/issues/1716 μ—μ„œ 증상을 μ„€λͺ…ν•œ λͺ¨λ“  μ‚¬λžŒκ³Ό λ§ˆμ°¬κ°€μ§€λ‘œ ν”„λ‘œμ νŠΈμ—μ„œλ„ λ™μΌν•œ 버그가 λ°œμƒν•©λ‹ˆλ‹€. μš”μ»¨λŒ€, X 좕은 μ‹œκ°„ 간격과 같은 큰 값을 처리 ν•  μˆ˜μ—†λŠ” κ²ƒμ²˜λŸΌ 보이며 μ–΄λ–»κ²Œ λ“  차트 λ Œλ”λ§μ„ μ—‰λ§μœΌλ‘œ λ§Œλ“­λ‹ˆλ‹€.

@sjuvvalapalem 원본 ChartsDemoκ°€ μ œλŒ€λ‘œ μž‘λ™ν•©λ‹ˆκΉŒ? λ‚˜λŠ” λ‹Ήμ‹ μ˜ 변화에 β€‹β€‹λŒ€ν•œ λ§₯락을 λͺ¨λ¦…λ‹ˆλ‹€. 차트 3.0μ—μ„œ x 값은 항상 두 λ°°μž…λ‹ˆλ‹€. λ³€κ²½ ν•œ 사항이 있으면 λͺ¨λ“  κ΄€λ ¨ ν•„λ“œλ₯Ό λ³€κ²½ν–ˆλŠ”μ§€ ν™•μΈν•˜μ‹­μ‹œμ˜€. 슀크린 샷에 λ§‰λŒ€κ°€ λˆ„λ½λ˜μ–΄ μžˆμœΌλ―€λ‘œ μžμ„Έν•œ λ‚΄μš©μ€ λ§‰λŒ€ 차트 λ Œλ”λŸ¬μ—μ„œ drawDataSets 을 (λ₯Ό) 확인할 수 μžˆλ‹€κ³  μƒκ°ν•©λ‹ˆλ‹€. μ‚¬μš©μž μΈ‘μ—μ„œ λ””λ²„κ·Έν•˜λŠ” 것이 더 μ‰½μŠ΅λ‹ˆλ‹€.

BarChartViewController.m.zip
@ liuxuan30 이전에 λ‹΅μž₯μ—μ„œ λ³€κ²½ ν•œ λ‚΄μš©μ„ μ²¨λΆ€ν–ˆμŠ΅λ‹ˆλ‹€.
λ‚΄κ°€ ν•œ 것은 일뢀 λ‚ μ§œμ— λŒ€ν•΄ Nstimeinterval을 두 번 μΆ”κ°€ν•˜λŠ” λŒ€μ‹  μ–΄λ–€ 이유둜 λ§‰λŒ€λ₯Ό ν‘œμ‹œν•˜μ§€ μ•ŠλŠ” κ²ƒμž…λ‹ˆλ‹€.

λ‚˜λŠ” 이것이 버그 일 수 μžˆλ‹€κ³  μƒκ°ν•œλ‹€. 첨뢀 된 zip λ¬Έμ„œλ₯Ό λ³΄μ‹œλ©΄ μ œκ°€ λ³€κ²½ ν•œ λ‚΄μš©μ„ μ‰½κ²Œ νŒŒμ•…ν•  수 있으며 이해가 될 κ²ƒμž…λ‹ˆλ‹€.
λ‹€λ₯Έ μ‚¬λžŒλ“€μ—κ²Œ λ™μΌν•œ 문제λ₯Ό μ‚΄νŽ΄λ³΄λ©΄ 이것이 버그 일 수 μžˆλ‹€κ³  μƒκ°ν•©λ‹ˆλ‹€.
λ‚΄ ν”„λ‘œμ νŠΈκ°€ μ•± μŠ€ν† μ–΄λ‘œ ν‘Έμ‹œλ˜λŠ” λŒ€μ‹  μ€‘λ‹¨λ˜κΈ° λ•Œλ¬Έμ— 이에 λŒ€ν•œ 도움은 크게 κ°μ‚¬λ“œλ¦½λ‹ˆλ‹€.

이것에 λŒ€ν•œ 해결책은 크게 도움이 될 κ²ƒμž…λ‹ˆλ‹€.

감사,
λ‹¨λ°œ

@ liuxuan30 이 문제λ₯Ό

감사,
λ‹¨λ°œ

μ΅œκ·Όμ— 일이 λ°”λΉ μ„œ λ„ˆλ¬΄ 빨리 λ³Ό μˆ˜κ°€ μ—†μ–΄μ„œ λ―Έμ•ˆ ν•΄μš”. μ‹œλ„ ν•  것이닀
NSTimeInterval은 λ‚΄κ°€ κΈ°μ–΅ν•˜λŠ” 두 λ°°μ΄λ―€λ‘œ 영ν–₯을 λ―ΈμΉ˜μ§€ μ•Šμ•„μ•Όν•©λ‹ˆλ‹€ ..

@ liuxuan30 λ„€, μ΄μ€‘μž…λ‹ˆλ‹€. 포맷터λ₯Ό μ‚¬μš©ν•˜λ©΄ λ‚ μ§œκ°€ μ˜¬λ°”λ₯΄κ²Œ ν‘œμ‹œλ©λ‹ˆλ‹€. λ§‰λŒ€ μœ„μ˜ 값이 μ˜¬λ°”λ₯΄κ²Œ ν‘œμ‹œλ©λ‹ˆλ‹€.

λͺ¨λ“  것이 μž‘λ™ν•˜μ§€λ§Œ λ§‰λŒ€κ°€ ν‘œμ‹œλ˜μ§€ μ•ŠμŠ΅λ‹ˆλ‹€.

λ°”μœ 경우이 문제 / 버그λ₯Ό 쑰사 ν•  μˆ˜μžˆλŠ” λ‹€λ₯Έ μ‚¬λžŒμ΄ μžˆμŠ΅λ‹ˆκΉŒ?

감사,
λ‹¨λ°œ

μ•Œκ² μŠ΅λ‹ˆλ‹€. κ°„λ‹¨νžˆ ν™•μΈν–ˆμŠ΅λ‹ˆλ‹€.
x μΆ• λ²”μœ„λŠ”

(lldb) po max - min
34041601.0

λ Œλ”λ§ ν•  λ•Œ barRect λ„ˆλΉ„κ°€ λ„ˆλ¬΄ μž‘μŠ΅λ‹ˆλ‹€.

β–Ώ (30.7373051480045, 132.310035326087, 8.28906013339292e-06, 257.842777173913)
  β–Ώ origin : (30.7373051480045, 132.310035326087)
    - x : 30.7373051480045
    - y : 132.310035326087
  β–Ώ size : (8.28906013339292e-06, 257.842777173913)
    - width : 8.28906013339292e-06 //  <-- you won't see it
    - height : 257.842777173913

κ·Έλž˜μ„œ 당신은 그것을 보지 λͺ»ν•©λ‹ˆλ‹€.
κ·Έ μ΄μœ λŠ” x val이 λ„ˆλ¬΄ μ»€μ„œ prepareBuffer() μ—μ„œ

let barWidthHalf = barData.barWidth / 2.0 // barWidthλŠ” 0.9μž…λ‹ˆλ‹€.

κ·Έλ•Œ

let left = CGFloat(x - barWidthHalf)
let right = CGFloat(x + barWidthHalf)
barRect.size.width = right - left

μ‚¬μ†Œν•œ μΌμž…λ‹ˆλ‹€.

@danielgindi λŠ” 큰 κ°€μΉ˜μ— λŒ€μ²˜ν•˜κΈ° μœ„ν•΄ barWidth λ₯Ό μ²˜λ¦¬ν•΄μ•Όν•˜λŠ” 것 κ°™μŠ΅λ‹ˆλ‹€. λ˜λŠ” 섀계에 μ˜ν•œ κ²ƒμž…λ‹ˆλ‹€.

x λ²”μœ„λŠ” 맀우 크지 만 λͺ‡ 개의 λ§‰λŒ€μ— λΆˆκ³Όν•˜μ§€λ§Œ ν•˜λ“œ μ½”λ”© 된 숫자λ₯Ό μ‚¬μš©ν•˜μ—¬ λ§‰λŒ€ λ„ˆλΉ„λ₯Ό ν‘œμ‹œν•˜λ―€λ‘œ λ¬Έμ œκ°€ λ°œμƒν•©λ‹ˆλ‹€. λ‚˜λŠ” barWidthλ₯Ό "μ •κ·œν™”"ν•˜λ €κ³  λ…Έλ ₯ν–ˆμŠ΅λ‹ˆλ‹€.

μž„μ‹œ ν•΄κ²° 방법은 x 값에 μ΄ˆκ°€ μ•„λ‹Œ 더 큰 일 λ‹¨μœ„λ₯Ό μ‚¬μš©ν•˜λŠ” κ²ƒμž…λ‹ˆλ‹€. λ˜λŠ” 1,2,3,4, ..둜 λ°”κΎΈκ³  포맷터가 ν¬λ§·ν•˜λ„λ‘ν•©λ‹ˆλ‹€. λ°μ΄ν„°μ—μ„œ x valsλŠ” 1 λ…„ 이상이며, 심지어 λ©°μΉ  λ™μ•ˆμ—λ„ 365 λ§‰λŒ€μ΄κ³  λ§‰λŒ€λ„ μ–‡μŠ΅λ‹ˆλ‹€.

또 λ‹€λ₯Έ 방법은 κ°€μΉ˜ λ²”μœ„μ— 맞게 barWidth λ₯Ό λ³€κ²½ν•˜λŠ” κ²ƒμž…λ‹ˆλ‹€. κ·ΈλŸ¬λ‚˜ μ˜¬λ°”λ₯Έ 번호λ₯Ό μ°ΎλŠ” 방법은 아직 λͺ…ν™•ν•˜μ§€ μ•ŠμŠ΅λ‹ˆλ‹€.

μ•ˆλ…•ν•˜μ„Έμš”,
λ‚˜λŠ” λ˜‘κ°™μ€ λ¬Έμ œκ°€ μžˆμ§€λ§Œ 해결책을주지 μ•Šκ³  λ¬Έμ œκ°€ λ‹«νžŒ 것 κ°™μŠ΅λ‹ˆλ‹€ ...
꺾은 μ„ ν˜• 차트λ₯Ό μ‚¬μš©ν•˜λ©΄ μ°¨νŠΈκ°€ μ œλŒ€λ‘œ κ·Έλ € μ§€μ§€λ§Œ μ„Έλ‘œ λ§‰λŒ€ 차트λ₯Ό μ„ νƒν•˜λ©΄ λ§‰λŒ€κ°€ λ‚˜νƒ€λ‚˜μ§€ μ•ŠμŠ΅λ‹ˆλ‹€.
λ‚˜μ—κ²Œ 그것은 κ°œμ„ μ΄ μ•„λ‹ˆλΌ λ²„κ·Έμž…λ‹ˆλ‹€.

감사

BarChartData.barWidthλ₯Ό 큰 κ°’ (~ 10 000)으둜 μ„€μ •ν•˜λ©΄ λ¬Έμ œκ°€ ν•΄κ²°λ˜μ—ˆμŠ΅λ‹ˆλ‹€.

ν…Œλ‘λ¦¬λ₯Ό μ„€μ •ν•˜μ—¬μ΄ 문제λ₯Ό ν•΄κ²°ν–ˆμŠ΅λ‹ˆλ‹€.
chartDataSet.barBorderColor = UIColor.blue
chartDataSet.barBorderWidth = 30
λ„μ›€μ΄λ˜λŠ” 희망

barBorderWidthλ₯Ό μ„€μ •ν•˜λ©΄ λ¬Έμ œκ°€ ν•΄κ²°λ˜λŠ” 것 κ°™μŠ΅λ‹ˆλ‹€.

이 λ¬Έμ œμ— λŒ€ν•œ 해결책이 μžˆμŠ΅λ‹ˆκΉŒ? barBorderWidth 섀정은 μž‘λ™ν•˜λŠ” κ²ƒμ²˜λŸΌ λ³΄μ΄μ§€λ§Œ 데이터 ν¬μΈνŠΈκ°€ ν•˜λ‚˜ λ˜λŠ” 2 개뿐이면 선이 λ„ˆλ¬΄ μ–‡κΈ° λ•Œλ¬Έμ— μ œλŒ€λ‘œ μž‘λ™ν•˜μ§€ μ•ŠμŠ΅λ‹ˆλ‹€ (barBorderWidthλ₯Ό 1둜 μ„€μ •ν–ˆλ‹€κ³  κ°€μ •). 더 높은 숫자둜 μ„€μ •ν•˜λ©΄ λͺ¨λ“  λ§‰λŒ€κ°€ κ²°ν•©λ˜κ³  μ„œλ‘œ μ„žμ—¬μ„œλ³΄κΈ°μ— 쒋지 μ•ŠμŠ΅λ‹ˆλ‹€.

이것에 λŒ€ν•œ λͺ¨λ“  μž‘μ—…μ€ λŒ€λ‹¨νžˆ κ°μ‚¬ν•©λ‹ˆλ‹€.

맀λ ₯처럼 μΌν•˜μ‹­μ‹œμ˜€!

bars not displaying

λ‚΄ 뢄석 :
이것은 λ²„κ·Έμž…λ‹ˆλ‹€ ... long 데이터 μœ ν˜•μ˜ λ‚ μ§œ 값은 1542039314621이며, SimpleDateFormat을 μ‚¬μš©ν•˜μ—¬ 포맷 된 ν›„ 2018 λ…„ 11 μ›” 12 일을 μ˜λ―Έν•©λ‹ˆλ‹€. κ·ΈλŸ¬λ‚˜ x AxisλŠ” λ¨Όμ € long 값을 μ·¨ν•˜λ―€λ‘œ λ¬Έμ œκ°€ λ°œμƒν•©λ‹ˆλ‹€. λ‚΄ μ†”λ£¨μ…˜μ€ xHelper, λŒ€μ‹  큰 값을 μž…λ ₯ν•˜κ³  xHelperλŠ” μ•”μ‹œ 적으둜 μΉ΄μš΄ν„° counter++ μ‚¬μš©ν•˜μ—¬ 인덱슀 long 데이터 μœ ν˜•μ„ μˆ˜ν–‰ν•˜κ³  xValue μ˜†μ— 큰 long 값을 λ³΄μœ ν•©λ‹ˆλ‹€. 이 μ½”λ“œλŠ” 맀λ ₯처럼 μž‘λ™ν•©λ‹ˆλ‹€.

이것은 잘λͺ»λœ μ½”λ“œμž…λ‹ˆλ‹€.

String[] month = new String[] {"Jan", "Feb", "Mar", "Aprl"};     
xAxis.setValueFormatter(new MyXAxisValueFormatter(month)); 

이것은 잘λͺ»λœ μ½”λ“œμž…λ‹ˆλ‹€.

 xAxis.setValueFormatter(new IAxisValueFormatter() {
         <strong i="20">@override</strong>
         public String getFormattedValue (float value, AxisBase axis){
              Date dates = new Date((long) value); //take your long value from BarEntry 
              SimpleDateFormat sdf = new SimpleDateFormat("dd/MM");
              return  sdf.format(dates);
              }
}

이것은 잘λͺ»λœ μ½”λ“œμž…λ‹ˆλ‹€.

for (int i = 0; i < xValues.length; i++)
Date date = new Date(xValues[i]);

이것은 잘λͺ»λœ μ½”λ“œμž…λ‹ˆλ‹€.

List<Date> dates = new ArrayList<Date>();
for (int i = 0; i< xHelper.length; i++)
dates.add(new Date(xValues[i]));

이 μ½”λ“œλŠ” 맀λ ₯처럼 μž‘λ™ν•©λ‹ˆλ‹€.

SimpleDateFormat sdf = new SimpleDateFormat("dd/MM"); // as you seen on the picture 
String[] xDates = new String[xHelper.length];
for (int m = 0; m < xHelper.length; m++) 
      xDates[m] = sdf.format(new Date(xValues[m]));

List<String> myDateList = new ArrayList<String>();
for (int n = 0; n < xHelper.length; n++)
      myDateList.add(xDates[n]);

//convert your ArrayList into array
String[] month = (String[]) myDateList.toArray(new String[xHelper.length]);

xAxis.setValueFormatter(new YourXAxisValueFormatter(month));

이것은 λ‚΄ 전체 μ½”λ“œμ΄λ©° xValue 및 xHelper에 λŒ€ν•œ λͺ¨λ“  것을 μ•Œλ €μ€λ‹ˆλ‹€.

public class MyDatabaseHelper {
long xValue
int xHelper, yValues;

//empty constructor
public MyDatabaseHelper(){
}

//constructor
public MyDatabaseHelper(long xValue, int yValues, int xHelper){
         this.xValue = xValue;
         this.yValue = yValue;
         this.xHelper = xHelper;
}

//Method
public long getxValue() {return xValues;}

public int getyValue() {return yValues;}

public int getxHelper() {return xHelper;}
}

λ‹€μŒμœΌλ‘œμ΄ μˆ˜μ—…μ„ λ§Œλ“€κ³  Phillip Jahodaμ—κ²Œ κ°μ‚¬λ“œλ¦½λ‹ˆλ‹€.

 public class MyXAxisValueFormatter implements IXAxisValueFormatter {
          private String[] mValues;`

          //constructor with array parameter
         public MyAxisValueFormatter(String[] values) {
                this.mValues = values;
          }

         <strong i="9">@override</strong>
         public String getFormattedValue(float value, AxisBase axis) {
              return mValues[(int) value];
         }
}

λ§ˆμ§€λ§‰μœΌλ‘œ MainActivity 클래슀λ₯Ό λ§Œλ“­λ‹ˆλ‹€.

public class MainActivity extends AppCompatActivity {

EditText yInput;
Button buttonInsert;
FirebaseDatabase firebaseDatabase;
DatabaseReference reference;
BarChart barChart;
//this is xHelper as counter for indexing x values
int counter = 0;

<strong i="13">@override</strong>
protected void onCreate (Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        yInput = (EditText) findViewById(R.id.editText);
        insertButton = (Button) findViewById(R.id.buttonInsert);
        firebaseDatabase = FirebaseDatabase.getInstance();
        reference = firebaseDatabase.getReference("ChartTable");
        insert();
  }
     public void insert() {
           buttonInsert.setOnClickListener(new View.OnClickListener() {
                   <strong i="14">@override</strong>
                    public void onClick (View v)
                    String id = reference.push().getKey();
                    long x = new Date().getTime();  //this is big value
                    int y = yInput.getText().toString();

                    // when you click button this counter increase
                    //note: using this counter will make your app being crash on 5 step Granularity
                    //my granularity is setGranularity(5);
                    //this is my problem and i don't know why. so, i have to make the counter start from zero
                    //like this                
                    counter++
                    int c = counter - 1;

                    // input value into class
                    MyDatabaseHelper db = new MyDatabaseHelper(x, y, c);
                    //input method into Firebase Database
                    reference.child(id).setValue(db);
           });
     }

    <strong i="15">@override</strong>
    protected void onStart {
    super.onStart();

                   reference.addValueEventListener(new ValueEventListener() {
                            <strong i="16">@override</strong>
                            public void onDataChange(<strong i="17">@NonNull</strong> DataSnapshot dataSnapshot) {

                                    int count = (int) dataSnapshot.getChildrenCount();
                                    long[] xValues = new long[count];
                                    int[] yValues = new int[count];
                                    int[] xHelper = new int[count];

                                    int index = 0;
                                    for (DataSnapshot myDataSnapshot : dataSnapshot.getChildren()){
                                    MyDatabaseHelper db = myDataSnapshot.getValue(MyDatabaseHelper.class);
                                    xValues[index] = db.getxValue();
                                    yValues[index] = db.getyValue();
                                    xHelper[index] = db.getxHelper();
                                    index++
                                   }

                                   ArrayList<BarEntry> barEntry = new ArrayList<BarEntry>();
                                   for (int i = 0; i < xHelper.length; i++)
                                         barEntry.add(new BarEntry(xHelper[i], yValues[i]));

                                   BarDataSet set1 = new BarDataSet(barEntry, "Project Progress");
                                   set1.setColors(ColorTemplate.VORDIPLOM_COLORS);
                                   set1.setDrawValues(false);                              

                                   ArrayList<IBarDataSet> dataSets =  new ArrayList<>();
                                   dataSets.add(set1);

                                   BarData data = new BarData(dataSets);

                                   XAxis xAxis = barChart.getXAxis();
                                   xAxis.setGranularity(5f);
                                   xAxis.setPosition(XAxis.XAxisPosition.BOTTOM);

                                   // input xValues[] into Date using List
                                   SimpleDateFormat sdf = new SimpleDateFormat("dd/MM");
                                   String[] xDates = new String[count];
                                   for (int m =0; m < xValues.length; m++)
                                         xDates[m] = sdf.format(new Date(xValues[m]));

                                  List<String> xDatesList = new ArrayList<String>();
                                  for (int n = 0; n < xDates.length; n++)
                                         xDatesList.add(xDates[n]);

                                  // you cannot insert xDatesList directly into setValueFormatter
                                  //so convert ArrayList into array
                                  String[] month = (String[]) xDatesList.toArray(new String[count]);

                                 //finally
                                 xAxis.setValueFormatter(new MyXAxisValueFormatter(month));
                                //done
                                barChart.getAxisRight().setEnabled(false);
                                barChart.setDragEnabled(true);
                                barChart.setScaleEnabled(true);
                                barChart.setPinchZoom(true);
                                barChart.setDoubleTapToZoomEnabled(false);
                                barChart.setDrawGridBackground(false);
                                barChart.setDragEnabled(true);

                                barChart.setData(data);
                                barChart.invalidate();


                             }
                             <strong i="18">@override</strong>
                             public void onCancelled(<strong i="19">@NonNull</strong> DatabaseError databaseError){
                            }
                   });
    }
} 

λͺ¨λ“  것이 μ™„λ£Œλ˜μ—ˆμŠ΅λ‹ˆλ‹€. 그리고 이것은 λ‚΄ μ„€λͺ…μž…λ‹ˆλ‹€.

이 μ½”λ“œλ₯Ό μ‚¬μš©ν•˜μ§€ μ•ŠμŠ΅λ‹ˆλ‹€.

String[] month = new String[] {"Jan", "Feb", "Mar", "Aprl"};     
xAxis.setValueFormatter(new MyXAxisValueFormatter(month)); 

동적 μž…λ ₯이 ν•„μš”ν•˜κ³  "jan", "feb"등을 μ“°κ³  싢지 μ•ŠκΈ° λ•Œλ¬Έμž…λ‹ˆλ‹€. λ‚΄ μ†”λ£¨μ…˜ :
String[] month = (String[]) myDateList.toArray(new String[xHelper.length]);

myDateList.toArray μ‚¬μš©ν•˜λ©΄ ArrayListλ₯Ό κ°€μ Έ μ™€μ„œ 배열에 μ‚½μž… ν•  수 μžˆμŠ΅λ‹ˆλ‹€.

그리고 μ €λŠ”μ΄ μ½”λ“œλ₯Ό μ‚¬μš©ν•˜μ§€ μ•ŠμŠ΅λ‹ˆλ‹€. μ™œλƒν•˜λ©΄->

xAxis.setValueFormatter(new IXAxisValueFormatter {

         <strong i="15">@override</strong>
         public String getFormattedValue(float value, AxisBase axis) {
              Date dates = new Date((long) value)
              SimpleDateFormat sdf = new SimpleDateFormat("dd/MM");
              return sdf.format(dates);
         }
}

λ§‰λŒ€κ°€ 사라진 x μΆ•μ—μ„œ κ°€μ Έμ˜¨ value λ•Œλ¬Έμž…λ‹ˆλ‹€. λ‚΄ μ†”λ£¨μ…˜μ€ λ‹€μŒκ³Ό 같이 xHelper .

ArrayList<BarEntry> barEntry = new ArrayList<BarEntry>();
for (int i=0; i<xHelper.length; i++)
    barEntry.add(new BarEnry(xHelper[i], yValues[i]));

μš”μ μ€ xHelper μΈλ±μ‹±μ„μœ„ν•œ μž‘μ€ 값을 ν¬ν•¨ν•΄μ•Όν•œλ‹€λŠ” κ²ƒμž…λ‹ˆλ‹€. Date

그리고 이것이 λΉ„λ°€μž…λ‹ˆλ‹€.
당신은 이것을 μ‚¬μš©ν•˜μ—¬ Date λ₯Ό μž…λ ₯ν•˜μ§€ μ•ŠμŠ΅λ‹ˆλ‹€-> String[] month = new String[]{...}; κ·ΈλŸ¬λ‚˜ myDateList

String[] month = (String[]) myDateList.toArray(new String[xHelper.length]);
xAxis.setValueFormatter(new YourXAxisValueFormatter(month));

@sjuvvalapalem @avitus에 λŒ€ν•œ 해결책을

이 버그가보고 된 지 2 년이 지났지 만 아직 μˆ˜μ •λ˜μ§€ μ•Šμ•˜μŠ΅λ‹ˆκΉŒ?

이 문제λ₯Ό ν•΄κ²°ν•˜κΈ° μœ„ν•΄ PR을 μ œμΆœν•  수 μžˆμŠ΅λ‹ˆκΉŒ? μ›λž˜ added this to To do in 4.0 Release 둜 ν‘œμ‹œν–ˆμŠ΅λ‹ˆλ‹€.

이것이 λˆ„κ΅¬μ—κ²Œλ„ λ„μ›€μ΄λ˜λŠ”μ§€ ν™•μ‹€ν•˜μ§€ μ•Šμ§€λ§Œ λ™μΌν•œ λ¬Έμ œκ°€ μžˆμ—ˆκ³  x μΆ• λ²”μœ„μ— λŒ€ν•΄ μ˜¬λ°”λ₯Έ 크기둜 λ§‰λŒ€λ₯Ό μ„€μ •ν•˜μ—¬ ν•΄κ²°ν–ˆμŠ΅λ‹ˆλ‹€.

let data = BarChartData(dataSets: [dataSet])

let dataSetRange = dataSet.xMax - dataSet.xMin
let availableSpacePerBar = dataSetRange / Double(dataSet.entryCount)
data.barWidth = availableSpacePerBar * 0.8 // 80% of available space

chartView.data = data

BarChartData.barWidthλ₯Ό 큰 κ°’ (~ 10 000)으둜 μ„€μ •ν•˜λ©΄ λ¬Έμ œκ°€ ν•΄κ²°λ˜μ—ˆμŠ΅λ‹ˆλ‹€.

이것은 데이터 λ²”μœ„ 사이에 λˆ„λ½ 된 κ°’μ΄μžˆμ„ λ•Œ https://github.com/danielgindi/Charts/issues/1742#issuecomment -519056482보닀 더 잘 μž‘λ™ν•©λ‹ˆλ‹€. λΉ„ 연속적이고주기적인 데이터 μ†ŒμŠ€.

κ·Έ 사이에 λˆ„λ½ 된 κ°’μ΄μžˆλŠ” 경우
λŒ“κΈ€ https://github.com/danielgindi/Charts/issues/1742#issuecomment -519056482 λ‹€μŒ
Screenshot 2020-05-16 at 12 52 11 PM

BarChartData.barWidthλ₯Ό 큰 κ°’ (~ 10 000)으둜 μ„€μ •ν•˜λ©΄ λ‹€μŒκ³Ό κ°™μŠ΅λ‹ˆλ‹€.
Screenshot 2020-05-16 at 12 52 40 PM

κ·ΈλŸ¬λ‚˜ 두 가지 λͺ¨λ‘ μΆ©λΆ„ν•œ 연속 값을 κ°€μ§ˆ λ•Œ ν›Œλ₯­ν•˜κ²Œ μž‘λ™ν•©λ‹ˆλ‹€.
IMG_81DD4290AE1B-1

이 λ•Œλ¬Έμ— 3 μ‹œκ°„μ„ μžƒμ—ˆμœΌλ‹ˆ 계속 μ£Όμ‹œν•˜κ³  μžˆμŠ΅λ‹ˆλ‹€. 인덱슀λ₯Ό μ‚¬μš©ν•˜μ—¬ λλ‚¬μŠ΅λ‹ˆλ‹€.

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