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

X/Y coordinates being rounded to whole numbers instead of being presented as decimals #4182

Closed
varunjitsingh6410 opened this issue Oct 17, 2019 · 1 comment

Comments

@varunjitsingh6410
Copy link

varunjitsingh6410 commented Oct 17, 2019

Hi all.

I am currently attempting to generate a scatterplot graph where many of the coordinates should be decimals. However, the values keep getting rounded to the closest whole number and I am not sure why nor can I find a solution.

Screen Shot 2019-10-17 at 9 13 14 AM

The above is a picture of the graph that is being generated. At the marker selected the points should be (x: 3/500 ; y: 3/500).

The code used to generate the graph is as follows:

for i in 0..<num {
            
            let coords = ChartDataEntry(x: Double(i/500), y: Double(i/500), data: ("Testing if points are decimal" as! String))
            dataPoints.append(coords)
}
        
self.graphView.drawMarkers = true
let marker:BalloonMarker = BalloonMarker(color: UIColor(red: 93/255, green: 186/255, blue: 215/255, alpha: 1), font: UIFont(name: "Helvetica", size: 12)!, textColor: UIColor.white, insets: UIEdgeInsets(top: 7.0, left: 7.0, bottom: 25.0, right: 7.0))
marker.minimumSize = CGSize(width: 75.0, height: 35.0)//CGSize(75.0, 35.0)
self.graphView.marker = marker

let set1 = ScatterChartDataSet(entries: self.dataPoints, label: self.graphName)
let data = ScatterChartData(dataSet: set1)
self.graphView.data = data
self.graphView.setVisibleXRangeMaximum(6)

Essentially my question is how can I get the correct decimal points mapped onto the graph without them being rounded?

@varunjitsingh6410
Copy link
Author

So it ended up being a non-charts related problem and something dumb I missed. i was not being casted to a double which is what cause the rounding error. The issue was resolved where I directly casted i into a double (e.g. Double(Double(i)/500)

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

1 participant