1. 程式人生 > >關於圖表第三方Charts的一些理解與總結

關於圖表第三方Charts的一些理解與總結

ups object init string div try nsf 一點 post

最近項目中用到了很多的圖表,如柱狀圖,線狀圖,餅狀圖等等。接觸到了一個新的第三方Charts,在做圖方面確實非常強大,在使用了一段時間後,今天對他進行一個小的總結,也是自己的一點小理解。

關於charts圖的基本的創建與一些基本的屬性就不多一一贅述了,下面說一下我平時用到的,大家可能理解不太深刻的一些屬性與用法。

(在這裏說一下,各種圖的屬性用法相似,我就不一一區分寫了,這篇文章針對的是一些對Charts有一定了解的人,自然也是能看懂的。)

  1.網格的形式:gridLineDashLengths = @[@3.0f,@3.0f] 網格線長度 網格線間的間隔 (如果想要實線只需要把數組後一個改成0.0f)

  2.X軸上數據的顯示:vauleFormatter 可自定義;granularity 刻度 =1時可防止因放大X軸引起的數據刻度變小。 也可理解為隔幾個顯示一個數值

  3.默認選中:

    [priceLineChartView highlightValueWithX:DateNameArray.count - 1 y:[LineDataArray.lastObject floatValue] dataSetIndex:0];

  4.多柱圖的設置: BarChartData *data = [[BarChartData alloc] initWithDataSets:dataSets];

          data.barWidth = 0.28;

           [data groupBarsFromX:-0.5 groupSpace:0.1 barSpace:0.02];

  5.選中疊加柱時,彈出MarkView的值的顯示:

open override func refreshContent(entry: ChartDataEntry, highlight: Highlight)

{

let indexNum:Int = highlight.stackIndex

let barEntry:BarChartDataEntry = entry as! BarChartDataEntry

if indexNum == -1 {

let yVal = String (format: "%.2f", barEntry.y)

setLabel(yVal)

}else {

let yVal = String (format: "%.2f", barEntry.yValues![indexNum])

setLabel(yVal)

}

}

  6.默認移動到特定位置:

  

    [priceLineChartView moveViewToAnimatedWithXValue:[priceLineChartView.data entryCount]-1 yValue:[priceLineChartView.data dataSetCount]-1     axis:AxisDependencyLeft duration:0.01];

  7.放大Charts:

    [priceLineChartView.viewPortHandler refreshWithNewMatrix:CGAffineTransformMakeScale(a * 1.3, 1.0) chart:priceLineChartView invalidate:YES];

   暫時就想到這麽多,有更好的需要添加的我會持續整理,有什麽問題也可以加我QQ530910944大家交流一下。

關於圖表第三方Charts的一些理解與總結