ChartsOrg / ChartsOrg/Charts

Stacked Bar Chart not working properly?

Open
#2,683 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
Swift
Stars
28k
Forks
6k
PR merge metrics
No merged PRs in 30d

Description

I'm really confused, **how** and **when** does `stringForValue` actually work?

I thought I knew how it is being called but I guess I don't.

I'm trying to combine data into one **stacked** bar if the x-axis values are the same, but I'm confused on when `stringForValue` is called to format the x-axis labels.

This is currently what I'm seeing:

![untitled](https://user-images.githubusercontent.com/8109158/29016545-ad0b51a8-7b07-11e7-8a5d-153a8c07c499.png)

I was **somewhat** able to combine the data from the date label `08/06/17` because there's 2 data for that x-axis date (as can be seen in the table below), but the upper red part should be `5.66`, not `8.66`. Somehow, it is adding `3.00` to `5.66` to make `8.66`.

However, that's not what I'm concerned about. I'm trying to eliminate the first blank `08/06/17` x-axis label, but for some reason, `stringForValue` is being called for each index.

Here's a bit of my code:

```
extension ServiceChargeViewController: IAxisValueFormatter
{
func stringForValue(_ value: Double, axis: AxisBase?) -> String
{
let tempServiceRecord_ARRAY = serviceRecord_ARRAY.sorted(by: {$0.date < $1.date})

print("value = \(value)")

let date = tempServiceRecord_ARRAY[Int(value)].date

print("date = \(date)")

return ReusableClass.typeThreeDateFormat(date: date)
}
}

func createBarChart(dataPoints: [Date], values: [Double])
{
var dataEntries: [BarChartDataEntry] = []

....

for lastIndex in 0..

Contributor guide

Open the contributing guide

Research direction

Start by tracing IAxisValueFormatter.stringForValue and BarChartDataEntry through the chart axis-labeling path, then reproduce the provided dataPoints, values, and x values in createBarChart. Determine why the formatter receives 0, 1, 2, 3, 4 instead of the entry positions, and verify that the repeated 08/06/17 label is eliminated without breaking stacked bars.

Written by the indexing model from the issue text.

Assessment

Tech stack
swift
Domain
data-visualization, mobile-dev
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.