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

My pie chart legends still not showing #1985

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

My pie chart legends still not showing #1985

nbnitin opened this issue Dec 20, 2016 · 4 comments

Comments

@nbnitin
Copy link

nbnitin commented Dec 20, 2016

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

    var dataEntries: [ChartDataEntry] = []
    
    //    ChartLegend *l = _chartView.legend;
    //    l.horizontalAlignment = ChartLegendHorizontalAlignmentRight;
    //    l.verticalAlignment = ChartLegendVerticalAlignmentTop;
    //    l.orientation = ChartLegendOrientationVertical;
    //    l.drawInside = NO;
    //    l.xEntrySpace = 7.0;
    //    l.yEntrySpace = 0.0;
    //    l.yOffset = 0.0;
    
    
    for i in 0..<dataPoints.count {
        let dataEntry1 = ChartDataEntry(x: Double(i), y: values[i])
        
        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.centerAttributedText = attribute
    pieChart.holeRadiusPercent = 0.6
    pieChart.chartDescription?.enabled = true
    
    var colors: [UIColor] = []
    let color1 = UIColor.blue
    colors.append(color1)
    
    let color2 = UIColor.brown
    colors.append(color2)
    pieChartDataSet.colors = colors
    
    pieChart.animate(xAxisDuration: 2.0, yAxisDuration: 2.0)
    
    let pieChartData = PieChartData(dataSet: pieChartDataSet)
    pieChart.data = pieChartData
}

override func viewDidLoad() {
super.viewDidLoad()
// setLeftChart()
distance = CGFloat(0.0)
setRightChart()

   let months : [String] = ["Jan", "feb"]
    let unitsSold = [25.0, 20.0]
     pieChart.delegate = self
    pieChart.legend.enabled = true
    let legend = pieChart.legend
    
    legend.horizontalAlignment = .center
    
    legend.drawInside = true   // can be true
    legend.xEntrySpace = 20.0
    legend.yEntrySpace = 20.0
    legend.yOffset = 0.0
    legend.textColor = UIColor.purple
    let enteries: [LegendEntry] = [LegendEntry(label: "Jan", form: .square, formSize: 4.0, formLineWidth: 10.0, formLineDashPhase: 0.0, formLineDashLengths: nil, formColor: UIColor.red), LegendEntry(label: "Feb", form: .square, formSize: 4.0, formLineWidth: 10.0, formLineDashPhase: 0.0, formLineDashLengths: nil, formColor: UIColor.orange)]
    legend.entries = enteries
    pieChart.legend.enabled = true
    setChart(months, unitsSold)
    
    
}
@liuxuan30
Copy link
Member

please don't create duplicated issues, 'closed' does not mean it will not get update.
As I said, you should refer ChartsDemo and ChartsDemo-OSX is in swift.

@nbnitin
Copy link
Author

nbnitin commented Dec 21, 2016 via email

@liuxuan30
Copy link
Member

well.. autolayout has nothing to do with chart, legend is drawn in the chart frame. So check out ChartsDemo.

@nbnitin
Copy link
Author

nbnitin commented Dec 27, 2016 via email

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

2 participants