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

App Crashing while updating BarChart with data #3945

Closed
sulaiman-mlbd opened this issue Apr 15, 2019 · 6 comments
Closed

App Crashing while updating BarChart with data #3945

sulaiman-mlbd opened this issue Apr 15, 2019 · 6 comments

Comments

@sulaiman-mlbd
Copy link

What did you do?

I wanted to show a bar chart. while configuring bar chart with data , my app get crashing
my code was
func updateBarChart() {

    let entry1 = BarChartDataEntry(x: 1.0, y: 10)
    let entry2 = BarChartDataEntry(x: 2.0, y: 20)
    let entry3 = BarChartDataEntry(x: 3.0, y: 30)
    let dataSet = BarChartDataSet([entry1, entry2, entry3])
    let data = BarChartData(dataSets: [dataSet])
    barChart.data = data
    //        barChart.chartDescription?.text = "Number of Widgets by Type”

    dataSet.colors = ChartColorTemplates.vordiplom()

    barChart.notifyDataSetChanged()
}

It was crashing on library part . I am adding details about where it crashed.
FileName: BarChartRenderer.swift
Line 79:
full library function code;
open override func initBuffers()
{
if let barData = dataProvider?.barData
{
// Matche buffers count to dataset count
if _buffers.count != barData.dataSetCount
{
while _buffers.count < barData.dataSetCount
{
_buffers.append(Buffer())
}
while _buffers.count > barData.dataSetCount
{
_buffers.removeLast()
}
}

        for i in stride(from: 0, to: barData.dataSetCount, by: 1)
        {
            **let set = barData.dataSets[i] as! IBarChartDataSet** // crashing on this line
            let size = set.entryCount * (set.isStacked ? set.stackSize : 1)
            if _buffers[i].rects.count != size
            {
                _buffers[i].rects = [CGRect](repeating: CGRect(), count: size)
            }
        }
    }
    else
    {
        _buffers.removeAll()
    }
}

What did you expect to happen?

This code was taken from your dummy project. It ran perfectly before. Now i don't know why crashing

Charts Environment

Charts version/Branch/Commit Number:
Xcode version: 10.2 updated
Swift version: 4.2
Platform(s) running Charts: iPhone XR emulator
macOS version running Xcode: mac OS Mojave
Screenshot 2019-04-15 at 7 18 50 PM

@simbo64
Copy link

simbo64 commented Apr 15, 2019

Have you tried cleaning the build folder and then re-building? I had an issue where the new code hadn't built properly

@scjc
Copy link

scjc commented Apr 15, 2019

I fixed this issue with a clean build (Cmd + Shift + K)

@anekk
Copy link

anekk commented Apr 23, 2019

Duplicate of #3917

@liuxuan30
Copy link
Member

Post the crash log.
from your code

let dataSet = BarChartDataSet([entry1, entry2, entry3])

it shouldn't fail to cast. So I need the crash message of the reason. your screenshot includes almost everything but the crash message.

Unlike #3917, it's crashed because it's passing in a ChartDataSet rather than a BarChartDataSet.

However you are saying you passed in BarChartDataSet. so it's why the crash message matters here. I don't know why it's crashed.

The ChartsDemo works fine though.

@liuxuan30
Copy link
Member

take a look at #3917, we found something that may causes the crash. closing as dup

@aksamitsah
Copy link

aksamitsah commented Jul 12, 2023

hi, i get issue i dont get any error during build when i run my app than runtime crash

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

No branches or pull requests

6 participants