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

Multiple DataSet Error #174

Closed
nhjariwala opened this issue Jun 25, 2015 · 1 comment
Closed

Multiple DataSet Error #174

nhjariwala opened this issue Jun 25, 2015 · 1 comment

Comments

@nhjariwala
Copy link

Earlier I have only one dataSet it works fine

    var xVals = Array<String>()
    for var i = 0 ; i < count ; i++ {
        xVals.append(months[i % 8])
    }

    var yValsTemp = Array<String>()
    for var i = 0 ; i < count ; i++ {
        yValsTemp.append(datas[i % 8])
    }

    var yVals = Array<BarChartDataEntry>();
    for var i = 0 ; i < yValsTemp.count ; i++ {
        yVals.append(BarChartDataEntry(value: (yValsTemp[i] as NSString).floatValue, xIndex: i))
    }

    var set1: BarChartDataSet = BarChartDataSet(yVals: yVals, label: "")
    var data: BarChartData = BarChartData(xVals: xVals, dataSet: set1)

I need to add one more dataSet so I have create another dataSet

    var zValsTemp = Array<String>()
    for var i = 0 ; i < count ; i++ {
        zValsTemp.append(dataSale[i % 8])
    }

    var zVals = Array<BarChartDataEntry>()
    for var i = 0 ; i < zValsTemp.count ; i++ {
        zVals.append(BarChartDataEntry(value: (zValsTemp[i] as NSString).floatValue, xIndex: i))
    }

    var set2: BarChartDataSet = BarChartDataSet(yVals: zVals, label: "")
    set2.setColor(UIColor.greenColor())

But I am not able to set Both dataSet together into final dataSet I have tried several thing
Attempt:1

    var dataSet = NSMutableArray(objects: set1,set2)

    var data: BarChartData = BarChartData(xVals: xVals, dataSet: dataSet)
    //Error:: Cannot find an initializer for type 'BarChartData' that accepts an argument list of type '(xVals: Array<String>, dataSet: NSMutableArray)'

Attempt:2

    var dataSet = NSMutableArray()
    dataSet.addObject(set1)
    dataSet.addObject(set2)

    var data: BarChartData = BarChartData(xVals: xVals, dataSet: dataSet)
    //Error:: Cannot find an initializer for type 'BarChartData' that accepts an argument list of type '(xVals: Array<String>, dataSet: NSMutableArray)'

Attempt:3

    var set = Array<BarChartDataSet>()
    set.append(set1)
    set.append(set2)

    var data: BarChartData = BarChartData(xVals: xVals, dataSet: set)
    //Error:: Cannot find an initializer for type 'BarChartData' that accepts an argument list of type '(xVals: Array<String>, dataSet: Array<BarChartDataSet>)

How can I setup both for multiple chart rendering.
Thanks

@nhjariwala
Copy link
Author

I have resolved the problem by changing in Attempt:3

    var data: BarChartData = BarChartData(xVals: xVals, dataSet: set)

to

    var data: BarChartData = BarChartData(xVals: xVals, dataSets: set)

Simply change dataSet to dataSets helps to resolve 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

1 participant