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

Legend label missing in pie chart #1980

Closed
nbnitin opened this issue Dec 19, 2016 · 4 comments
Closed

Legend label missing in pie chart #1980

nbnitin opened this issue Dec 19, 2016 · 4 comments

Comments

@nbnitin
Copy link

nbnitin commented Dec 19, 2016

I am using below code , it showing me value on my pie slices and colors in legend but not title or text of it .
Like ["jan","feb"] this is not showing not values are there , how can i rectify this?

func setChart(dataPoints: [String], values: [Double]) {

    var dataEntries: [ChartDataEntry] = []
    

    
    
    for i in 0..<dataPoints.count {
        let dataEntry1 = ChartDataEntry(x: Double(i), y: values[i], data: dataPoints[i] as AnyObject?)
        
        dataEntries.append(dataEntry1)
        
    }
    
    
   
let pieChartDataSet = PieChartDataSet(values: dataEntries, label: "hello")
    
    pieChartDataSet.sliceSpace = 2
    
    pieChartDataSet.yValuePosition = .outsideSlice
    
    
    let text = "Total \n Rs 100000"
   
    
    let style = NSMutableParagraphStyle()
    style.alignment = .center
    let attributes = [
        
        NSParagraphStyleAttributeName: style
    ]

    
    let range = (text as NSString).range(of: "Total")
    
    let attribute = NSMutableAttributedString.init(string: text)
    attribute.addAttribute(NSForegroundColorAttributeName, value: UIColor.lightGray , range: range)
    attribute.addAttributes(attributes, range: range)
    
   
    
    pieChart.drawEntryLabelsEnabled = true
    
    pieChart.centerAttributedText = attribute
          pieChart.holeRadiusPercent = 0.6
   pieChart.chartDescription?.enabled = false
    
   pieChart.legend.enabled  = true
pieChart.legend.direction = .rightToLeft
   
    
    var colors: [UIColor] = []
    
    let color1 = UIColor(hexString: "#1A3E72")
    colors.append(color1)
    
    let color2 = UIColor(hexString: "#2D9C3D")
    colors.append(color2)
    pieChartDataSet.colors = colors

    
 pieChart.animate(xAxisDuration: 2.0, yAxisDuration: 2.0)
   
    let pieChartData = PieChartData(dataSet: pieChartDataSet)
    
    
    pieChart.legend.enabled = true
    pieChart.data = pieChartData
   
    
   
    
    
    
    
    
}

let months = ["Jan", "Feb"]
let unitsSold = [25.0, 20.0]

@TheAbhiGoyal
Copy link

Mention the legend.enteries and make sure you're configuring legends before providing the dataSet.

@liuxuan30
Copy link
Member

Check out ChartsDemo for details as well

@nbnitin
Copy link
Author

nbnitin commented Dec 20, 2016 via email

@liuxuan30
Copy link
Member

well you should get familiar with objc. Besides, the code is pretty straight forward, even you don't know objc, you can know from its names, it's 99% consistent between objc and swift.
Bottom line: ChartsDemo-OSX is in swift.

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