Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bar chart is plotting for empty value and Line chart is not appeared in CombinedChartView #3511

Closed
muthusabarinathan opened this issue Jun 13, 2018 · 4 comments

Comments

@muthusabarinathan
Copy link

muthusabarinathan commented Jun 13, 2018

What did you do?

I would like to create a chart for stocks price and volume. So I chooses combinedChartView. I would like to show date in xAxis. I tried it with charts-swift demo code.

What did you expect to happen?

My expectation is to show price value as LineChart and Volume value as Bar chart like below mentioned Image.

screen shot 2018-06-13 at 5 28 46 pm

What happened instead?

But when i tried the demo chart using my values, I got bar chart alone instead of combine the line chart.

And also am passing only 5 values. But chart shows 7 values, Jun 9 and Jun 10 is also plotting with no bar(I don't pass Jun 9 and Jun 10).

screen shot 2018-06-13 at 5 23 17 pm

Herewith I attached my demo project file:

CombinedChartViewController.swift.zip

Charts Environment

Charts version/Branch/Commit Number: 3.1.1
Xcode version: 9.2
Swift version: 3.2
Platform(s) running Charts: iOS
macOS version running Xcode: 10.13.1

Please help me to achieve this.

@thierryH91200
Copy link
Contributor

you are confusing date and interval

change

extension ChartXAxisFormatter: IAxisValueFormatter {
    func stringForValue(_ value: Double, axis: AxisBase?) -> String {
        var date: [String]! = ["2018-06-12","2018-06-11","2018-06-08","2018-06-07","2018-06-06"]
        
        public func stringForValue(_ value: Double, axis: AxisBase?) -> String
        {
            return date[ Int(value) ]
        }
    }
}

and
date -> i

       for i in 0 ..< dateArr.count {
            let date = dateFormatter.date(from: dateArr[i])
            let yValue1: Double = Double(priceArr[i])
            let yValue2: Double = Double(volumeArr[i])
            let dataPoints = DataPointsValue(_xDate: i, _value1: yValue1, _value2: yValue2)
            chartData.append(dataPoints)
        }

@muthusabarinathan
Copy link
Author

@thierryH91200 - Thank you so much. It perfectly works. Can you have any idea to draw bar chart in bottom like my expectation image.

@thierryH91200
Copy link
Contributor

I did not understand the question sorry

@muthusabarinathan
Copy link
Author

Nothing. I fixed it. Thanks for your valuable solutions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants