2013-06-05 65 views
2

我的一個ipad項目需要有8種圖形和圖表,其中包括3個變量泡泡圖,散點圖,燭臺圖等等。快速搜索給出了我作爲核心圖的結果這是目前ios中圖形和圖表最常用的解決方案。但是當我進入頁面時,我沒有看到任何類型的氣泡圖或散點圖實現。我的問題是..使用核心圖的泡沫圖,散點圖,燭臺圖

  • 是否有可能畫出3可變氣泡圖,散點圖或燭臺圖中coreplot ??或我需要使用芯圖形繪製整個圖形?

在此先感謝

回答

3

核心地塊原生支持散點圖和K線圖。通過使用散點圖的自定義繪圖符號和改變繪圖符號的大小來表示第三個變量,您可以輕鬆製作氣泡圖。

如果你想只實現 散點圖這裏
0

是在迅速3.1的Xcode 8.3.2

func setChart(dataPoints:[String] , value1 :[Double] , value2:[Double]) 
{ 
    var dataEntries1:[ChartDataEntry] = [] 

    for i in 0..<dataPoints.count { 
     let dataEntry = ChartDataEntry(x:value1[i] , y : Double(i)) 
     dataEntries1.append(dataEntry) 
    } 

    var dataEntries2:[ChartDataEntry] = [] 

    for i in 0..<dataPoints.count { 
     let dataEntry = ChartDataEntry(x:value2[i] , y : Double(i)) 
     dataEntries2.append(dataEntry) 
    } 

    let dataSet1 = ScatterChartDataSet(values: dataEntries1, label: "Value1") 
    dataSet1 .setColor(UIColor.blue) 
    let dataSet2 = ScatterChartDataSet(values: dataEntries2 ,label: "Value2") 
    dataSet2.setColor(UIColor.green) 

    var dataSets = [ScatterChartDataSet]() 
    dataSets.append(dataSet1) 
    dataSets.append(dataSet2) 

    let barChartData = ScatterChartData(dataSets: dataSets) 

    scatterChart.xAxis.labelPosition = .bottom 
    scatterChart.rightAxis.enabled=false 
    scatterChart.legend.enabled=false 
    scatterChart.descriptionText = "" 
    scatterChart.data = barChartData 

} 
0

這裏工作得很好的代碼添加到裏面氣泡圖代碼你應用

這個代碼在雨燕3.1和Xcode中8.3.2

func setBubbleChart(dataPoints: [Int], values: [Int], amounts: [Int]) { 

     var dataEntries: [BubbleChartDataEntry] = [] 

     for i in 0..<dataPoints.count { 
      let dataEntry = BubbleChartDataEntry(x: Double(dataPoints[i]), y: Double(values[i]), size: 15.0) 
      dataEntries.append(dataEntry) 
     } 

     let format = NumberFormatter() 
     format.generatesDecimalNumbers = false 
     format.zeroSymbol = "" 
     _ = DefaultValueFormatter(formatter: format) 

     let chartDataSet = BubbleChartDataSet(values: dataEntries, label: "Prashant") 
     let chartData = BubbleChartData(dataSet: chartDataSet) 



     chartDataSet.colors.append(setColor(value:30)) 

     bubbleChartView.doubleTapToZoomEnabled = true 
     bubbleChartView.scaleXEnabled = true 
     bubbleChartView.scaleYEnabled = true 
     bubbleChartView.highlightPerTapEnabled = true 
     bubbleChartView.highlightPerDragEnabled = true 

     let firstLegend = LegendEntry.init(label: "Below 50", form: .default, formSize: CGFloat.nan, formLineWidth: CGFloat.nan, formLineDashPhase: CGFloat.nan, formLineDashLengths: nil, formColor: UIColor.black) 
     let secondLegend = LegendEntry.init(label: "Between 50 and 75", form: .default, formSize: CGFloat.nan, formLineWidth: CGFloat.nan, formLineDashPhase: CGFloat.nan, formLineDashLengths: nil, formColor: UIColor.black) 
     let thirdLegend = LegendEntry.init(label: "Over 75", form: .default, formSize: CGFloat.nan, formLineWidth: CGFloat.nan, formLineDashPhase: CGFloat.nan, formLineDashLengths: nil, formColor: UIColor.black) 

     bubbleChartView.chartDescription = nil 
     bubbleChartView.legend.entries = [firstLegend, secondLegend, thirdLegend] 
     bubbleChartView.data = chartData 
     bubbleChartView.drawBordersEnabled = true 
     bubbleChartView.animate(xAxisDuration: 5.0, yAxisDuration: 5.0) 

     let xAxis: XAxis = bubbleChartView.xAxis 
     xAxis.drawAxisLineEnabled = true 
     xAxis.drawGridLinesEnabled = true 
     xAxis.drawLabelsEnabled = true 
     xAxis.axisMinimum = 0 
     xAxis.axisMaximum = 10 

     let leftAxis: YAxis = bubbleChartView.leftAxis 
     leftAxis.drawAxisLineEnabled = true 
     leftAxis.drawGridLinesEnabled = true 
     leftAxis.setLabelCount(2, force: true) 
     leftAxis.axisMinimum = 0 
     leftAxis.axisMaximum = 120 

     let rightAxis: YAxis = bubbleChartView.rightAxis 
     rightAxis.drawAxisLineEnabled = false 
     rightAxis.drawGridLinesEnabled = true 
     rightAxis.drawLabelsEnabled = false 
    }