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

Chart displays intermittently #2527

Closed
pktrkts opened this issue Jun 16, 2017 · 1 comment
Closed

Chart displays intermittently #2527

pktrkts opened this issue Jun 16, 2017 · 1 comment

Comments

@pktrkts
Copy link

pktrkts commented Jun 16, 2017

Hi,

By the way, in general I think the library is a great library. To the builders of this library, I say thanks.

So sometimes when I try to get chart to display, it shows the legend and the title, but doesn't show the chart itself. I've checked and the data being submitted to the chart is fine- as best as I can tell, sometimes it just refuses to display a chart. Usually, it's with the pie chart (though I think the bar chart may have displayed the same behavior, that doesn't happen as frequently). Here is the bulk of the code for setting up the pie chart: let chart = getChartObject() as! PieChartView
chart.drawHoleEnabled = false
/chart.isUsePercentValuesEnabled = true/
var values = myPieChartData.secondsPerSection
var sum = 0
for a in 0...values.count - 1
{
sum += values[a]
}
var outputSolutions: [PieChartDataEntry] = []
for b in 0...values.count - 1
{
var myVal: PieChartDataEntry
let (h, m, s) = secondsToHoursMinutesSeconds(seconds: Double(values[b]))
assert (sum > 0)
if sum > 0
{
myVal = PieChartDataEntry(value: Double(values[b] / sum * 100), label: "(Int(h)) hrs (Int(m)) mins")
}
else
{
myVal = PieChartDataEntry(value: 0.0, label: "0 hrs 0 mins")
}
outputSolutions.append(myVal)
}
var myDataSet = PieChartDataSet(values: outputSolutions, label: getChartTitle())
setDatasetColors(myDataSet: myDataSet)
var myChartSet: [IChartDataSet] = []
myChartSet.append(myDataSet)
var myData = PieChartData(dataSets: myChartSet)
chart.data = myData`

Thanks for your consideration of this matter.

Sincerely,
Sean

@pktrkts
Copy link
Author

pktrkts commented Jun 18, 2017

I figured it out! I had recently changed values to being integers instead of doubles. It was dividing and not getting an integer, so it rounded to zero. Casting values[b] to a double and casting sum to a double before dividing solved the problem.

@pktrkts pktrkts closed this as completed Jun 18, 2017
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