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

Down-casted Array element failed to match the target type #121

Closed
nhjariwala opened this issue Jun 1, 2015 · 8 comments
Closed

Down-casted Array element failed to match the target type #121

nhjariwala opened this issue Jun 1, 2015 · 8 comments

Comments

@nhjariwala
Copy link

Getting error on swift

    var set1: BarChartDataSet = BarChartDataSet(yVals: yVals, label: "")

while setting dataSet and its redirected to class BarChartDataSet in below function

/// calculates the maximum stacksize that occurs in the Entries array of this DataSet
private func calcStackSize(yVals: [BarChartDataEntry]!)
{
    for (var i = 0; i < yVals.count; i++)
    {
        var vals = yVals[i].values; // Error here

        if (vals != nil && vals.count > _stackSize)
        {
            _stackSize = vals.count;
        }
    }
}
@danielgindi
Copy link
Collaborator

So your array contains element of the wrong type...

‏בתאריך יום שני, 1 ביוני 2015, nhjariwala [email protected] כתב:

Getting error on swift

var set1: BarChartDataSet = BarChartDataSet(yVals: yVals, label: "")

while setting dataSet and its redirected to class BarChartDataSet in below
function

/// calculates the maximum stacksize that occurs in the Entries array of this DataSet
private func calcStackSize(yVals: [BarChartDataEntry]!)
{
for (var i = 0; i < yVals.count; i++)
{
var vals = yVals[i].values; // Error here

    if (vals != nil && vals.count > _stackSize)
    {
        _stackSize = vals.count;
    }
}

}


Reply to this email directly or view it on GitHub
#121.

@nhjariwala
Copy link
Author

here is the code

let months =
[
    "19/03/2015", "18/03/2015", "17/03/2015", "16/03/2015"
]

    var xVals = Array<String>()
    xVals.append(months[0])
    xVals.append(months[1])
    xVals.append(months[2])
    xVals.append(months[3])

    var yVals = Array<ChartDataEntry>();
    yVals.append(ChartDataEntry(value: 10.0, xIndex: 0))
    yVals.append(ChartDataEntry(value: 20.0, xIndex: 1))
    yVals.append(ChartDataEntry(value: 30.0, xIndex: 2))
    yVals.append(ChartDataEntry(value: 15.0, xIndex: 3))

    var set1: BarChartDataSet = BarChartDataSet(yVals: yVals, label: "")

    var data: BarChartData = BarChartData(xVals: xVals, dataSet: set1)
    mBarChart.data = data
}

Can you please point out the error ?
Thnx

@danielgindi
Copy link
Collaborator

Do you seriously do not see how casting ChartDataEntry "down" to
BarChartDataEntry would give you such an error?

‏בתאריך יום שני, 1 ביוני 2015, nhjariwala [email protected] כתב:

here is the code

let months =
[
"19/03/2015", "18/03/2015", "17/03/2015", "16/03/2015"
]

var xVals = Array<String>()
xVals.append(months[0])
xVals.append(months[1])
xVals.append(months[2])
xVals.append(months[3])

var yVals = Array<ChartDataEntry>();
yVals.append(ChartDataEntry(value: 10.0, xIndex: 0))
yVals.append(ChartDataEntry(value: 20.0, xIndex: 1))
yVals.append(ChartDataEntry(value: 30.0, xIndex: 2))
yVals.append(ChartDataEntry(value: 15.0, xIndex: 3))

var set1: BarChartDataSet = BarChartDataSet(yVals: yVals, label: "")

var data: BarChartData = BarChartData(xVals: xVals, dataSet: set1)
mBarChart.data = data

}

Can you please point out the error ?
Thnx


Reply to this email directly or view it on GitHub
#121 (comment)
.

@nhjariwala
Copy link
Author

I have tried several thing from Objective-C demo but not getting success So I have found the LineChart Samples on #29 So I have tried same thing on BarChart.

@danielgindi
Copy link
Collaborator

You should really read the code at the point where it expects a
BarChartDataEntry

‏בתאריך יום שני, 1 ביוני 2015, nhjariwala [email protected] כתב:

I have tried several thing from Objective-C demo but not getting success
So I have found the LineChart Samples on #29
#29 So I have tried
same thing on BarChart.


Reply to this email directly or view it on GitHub
#121 (comment)
.

@nhjariwala
Copy link
Author

Opps extremely silly mistake I haven't figured out it .. Thanks you so much for point out this .

@sodeve19
Copy link

Hi @nhjariwala, can you say what was the mistake? Thanks

@nhjariwala
Copy link
Author

Hi @sodeve19 ,
Earlier I was used the

    var yVals = Array<ChartDataEntry>();

but need to change DataEntry as per the chart in my case I used BarChart so

    var yVals = Array<BarChartDataEntry>();

and it was resolved the issue. Thanks ;)

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

3 participants