欧美三区_成人在线免费观看视频_欧美极品少妇xxxxⅹ免费视频_a级毛片免费播放_鲁一鲁中文字幕久久_亚洲一级特黄

如何用Core Plot繪制柱狀圖

系統(tǒng) 1932 0

Core Plot提供了柱狀圖的繪制,不足的是,只有垂直柱狀圖,沒有提供水平柱狀圖。期待下一版本的實(shí)現(xiàn)。

1、新建Windows-base Application。加入對(duì)Core Plot框架的引用。這里我們假設(shè)使用了Core Plot SDK ,項(xiàng)目設(shè)置參考前一博文《Core Plot SDK的用法》。

2、新建ViewController,首先修改ViewController的頭文件,import CorePlot.h,同時(shí)實(shí)現(xiàn)CPPlotDataSource協(xié)議,增加一個(gè)CPGraph變量:

#import <UIKit/UIKit.h>

#import <CorePlot/CorePlot.h>

@interface BarChartViewController : UIViewController <CPPlotDataSource>

{

@private

CPXYGraph * barChart ;

}

@property ( readwrite , retain , nonatomic ) NSTimer *timer;

@end

3、具體實(shí)現(xiàn)如下:

-( void )viewDidAppear:( BOOL )animated

{

// CPGraph 指定主題

barChart = [[ CPXYGraph alloc ] initWithFrame : CGRectZero ];

CPTheme *theme = [ CPTheme themeNamed : kCPDarkGradientTheme ];

[ barChart applyTheme :theme];

// self.view UIView 轉(zhuǎn)變?yōu)? CPGraphHostingView ,因?yàn)? UIView 無(wú)法加載 CPGraph

self . view =[[ CPGraphHostingView alloc ] initWithFrame :[ UIScreen mainScreen ]. bounds ];

CPGraphHostingView *hostingView = ( CPGraphHostingView *) self . view ;

[hostingView setHostedGraph : barChart ];

// CPGraph 邊框:無(wú)

barChart . plotAreaFrame . borderLineStyle = nil ;

barChart . plotAreaFrame . cornerRadius = 0.0f ;

// CPGraph 四邊不留白

barChart . paddingLeft = 0.0f ;

barChart . paddingRight = 0.0f ;

barChart . paddingTop = 0.0f ;

barChart . paddingBottom = 0.0f ;

// 繪圖區(qū) 4 邊留白

barChart . plotAreaFrame . paddingLeft = 70.0 ;

barChart . plotAreaFrame . paddingTop = 20.0 ;

barChart . plotAreaFrame . paddingRight = 20.0 ;

barChart . plotAreaFrame . paddingBottom = 80.0 ;

//CPGraph 標(biāo)題

barChart . title = @"Graph Title" ;

// SDK CPMutableTextStyle 不可用,用 CPTextStyle 替代

CPTextStyle * textStyle=[ CPTextStyle textStyle ];

// CPMutableTextStyle *textStyle = [CPTextStyle textStyle];

textStyle. color = [ CPColor grayColor ];

textStyle. fontSize = 16.0f ;

barChart . titleTextStyle = textStyle;

barChart . titleDisplacement = CGPointMake ( 0.0f , - 20.0f );

barChart . titlePlotAreaFrameAnchor = CPRectAnchorTop ;

// 繪圖空間 plot space

CPXYPlotSpace *plotSpace = ( CPXYPlotSpace *) barChart . defaultPlotSpace ;

// 繪圖空間大小: Y 0-300 , x 0-16

plotSpace. yRange = [ CPPlotRange plotRangeWithLocation : CPDecimalFromFloat ( 0.0f ) length : CPDecimalFromFloat ( 300.0f )];

plotSpace. xRange = [ CPPlotRange plotRangeWithLocation : CPDecimalFromFloat ( 0.0f ) length : CPDecimalFromFloat ( 16.0f )];

// 坐標(biāo)系

CPXYAxisSet *axisSet = ( CPXYAxisSet *) barChart . axisSet ;

//x 軸:為坐標(biāo)系的 x

CPXYAxis *x = axisSet. xAxis ;

CPLineStyle * lineStyle=[[ CPLineStyle alloc ] init ];

lineStyle. lineColor =[ CPColor greenColor ];

lineStyle. lineWidth = 1.0f ;

//x 軸:線型設(shè)置

x. axisLineStyle = lineStyle;

// 大刻度線:線型設(shè)置

x. majorTickLineStyle = lineStyle;

// 大刻度線:長(zhǎng)度

x. majorTickLength = 10 ;

// 小刻度線:無(wú)

x. minorTickLineStyle =lineStyle;

// 小刻度線:長(zhǎng)度

x. minorTickLength = 5 ;

// 大刻度線間隔單位: 5 個(gè)單位

x. majorIntervalLength = CPDecimalFromString ( @"5" );

// 直角坐標(biāo): 0

x. orthogonalCoordinateDecimal = CPDecimalFromString ( @"0" );

// 標(biāo)題

x. title = @"X Axis" ;

// 標(biāo)題位置: 7.5 單位

x. titleLocation = CPDecimalFromFloat ( 7.5f );

// 向下偏移: 55.0

x. titleOffset = 55.0f ;

//y

CPXYAxis *y = axisSet. yAxis ;

//y 軸:線型設(shè)置

y. axisLineStyle = lineStyle;

//y 軸:線型設(shè)置

y. majorTickLineStyle = lineStyle;

//y 軸:不顯示小刻度線

y. minorTickLineStyle = nil ;

// 大刻度線間距: 50 單位

y. majorIntervalLength = CPDecimalFromString ( @"50" );

// 坐標(biāo)原點(diǎn): 0

y. orthogonalCoordinateDecimal = CPDecimalFromString ( @"0" );

// 軸標(biāo)題

y. title = @"Y Axis" ;

y. titleOffset = 45.0f ;

y. titleLocation = CPDecimalFromFloat ( 150.0f );

// 1 個(gè)柱狀圖:黑色

CPBarPlot *barPlot = [ CPBarPlot tubularBarPlotWithColor :[ CPColor darkGrayColor ] horizontalBars : NO ];

barPlot. baseValue = CPDecimalFromString ( @"1" );

// 數(shù)據(jù)源,必須實(shí)現(xiàn) CPPlotDataSource 協(xié)議

barPlot. dataSource = self ;

// 圖形向左偏移: 0.25

barPlot. barOffset = - 0.25f ;

//id ,根據(jù)此 id 來區(qū)分不同的 plot ,或者為不同 plot 提供不同數(shù)據(jù)源

barPlot. identifier = @"Bar Plot 1" ;

// 添加圖形到繪圖空間

[ barChart addPlot :barPlot toPlotSpace :plotSpace];

// 2 個(gè)柱狀圖:藍(lán)色

barPlot = [ CPBarPlot tubularBarPlotWithColor :[ CPColor blueColor ] horizontalBars : NO ];

// 數(shù)據(jù)源,必須實(shí)現(xiàn) CPPlotDataSource 協(xié)議

barPlot. dataSource = self ;

// 柱子的起始基線:即最下沿的 y 坐標(biāo)

barPlot. baseValue = CPDecimalFromString ( @"1" );

// 圖形向右偏移: 0.25

barPlot. barOffset = 0.25f ;

// SDK 中, barCornerRadius cornerRadius 替代

barPlot. cornerRadius = 2.0f ;

//barPlot.barCornerRadius = 2.0f;

//id ,根據(jù)此 id 來區(qū)分不同的 plot ,或者為不同 plot 提供不同數(shù)據(jù)源

barPlot. identifier = @"Bar Plot 2" ;

// 添加圖形到繪圖空間

[ barChart addPlot :barPlot toPlotSpace :plotSpace];

}

- ( void )didReceiveMemoryWarning {

[ super didReceiveMemoryWarning ]; // Releases the view if it doesn't have a superview

// Release anything that's not essential, such as cached data

}

#pragma mark -

#pragma mark Plot Data Source Methods

// 返回?cái)?shù)據(jù)源的紀(jì)錄數(shù)

-( NSUInteger )numberOfRecordsForPlot:( CPPlot *)plot {

return 16 ;

}

// 返回?cái)?shù)據(jù)源的數(shù)據(jù)

-( NSNumber *)numberForPlot:( CPPlot *)plot field:( NSUInteger )fieldEnum recordIndex:( NSUInteger )index

{

// 返回類型是一個(gè) NSNumber

NSDecimalNumber *num = nil ;

// 如果圖形類型是 柱狀圖

if ( [plot isKindOfClass :[ CPBarPlot class ]] ) {

// 根據(jù)情況,柱狀圖的每一點(diǎn)都需要返回兩種數(shù)據(jù):位置( x 軸),長(zhǎng)度( y 軸)

switch ( fieldEnum ) {

//x 軸坐標(biāo)(柱子位置):

case CPBarPlotFieldBarLocation :

num = ( NSDecimalNumber *)[ NSDecimalNumber numberWithUnsignedInteger :index];

break ;

//y 軸坐標(biāo)(柱子長(zhǎng)度):

//SDK 中,枚舉 CPBarPlotField 只有兩個(gè)值 CPBarPlotFieldBarLocation = 2, 或者 CPBarPlotFieldBarLength = 3

case CPBarPlotFieldBarLength :

//case CPBarPlotFieldBarTip:

num = ( NSDecimalNumber *)[ NSDecimalNumber numberWithUnsignedInteger :(index+ 1 )*(index+ 1 )];

// 對(duì)于第 2 個(gè)圖形的點(diǎn)的 y 值,在第一個(gè)圖形的基礎(chǔ)上減去 10

if ( [plot. identifier isEqual : @"Bar Plot 2" ] )

num = [num decimalNumberBySubtracting :[ NSDecimalNumber decimalNumberWithString : @"10" ]];

break ;

}

}

return num;

}

-( CPFill *) barFillForBarPlot:( CPBarPlot *)barPlot recordIndex:( NSNumber *)index;

{

return nil ;

}

運(yùn)行效果如下:

如何用Core Plot繪制柱狀圖

如何用Core Plot繪制柱狀圖


更多文章、技術(shù)交流、商務(wù)合作、聯(lián)系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號(hào)聯(lián)系: 360901061

您的支持是博主寫作最大的動(dòng)力,如果您喜歡我的文章,感覺我的文章對(duì)您有幫助,請(qǐng)用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點(diǎn)擊下面給點(diǎn)支持吧,站長(zhǎng)非常感激您!手機(jī)微信長(zhǎng)按不能支付解決辦法:請(qǐng)將微信支付二維碼保存到相冊(cè),切換到微信,然后點(diǎn)擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對(duì)您有幫助就好】

您的支持是博主寫作最大的動(dòng)力,如果您喜歡我的文章,感覺我的文章對(duì)您有幫助,請(qǐng)用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長(zhǎng)會(huì)非常 感謝您的哦!!!

發(fā)表我的評(píng)論
最新評(píng)論 總共0條評(píng)論
主站蜘蛛池模板: 成人亚洲国产精品久久 | 欧美日韩午夜精品 | 影音先锋中文字幕一区 | 91高清网站 | 99久久国产综合精品网成人影院 | 午夜国产精品视频在线 | 在线视频97| 狠狠综合久久av一区二区小说 | 青草青草久热精品视频在线网站 | 激情小说综合 | 91看片淫黄大片在看 | 狠狠久| 欧美一级免费 | 亚洲精品一区二区三区福利 | 黑人精品欧美一区二区蜜桃 | youjizz欧美 | 国产福利观看 | 在线观看网 | 99亚洲精品高清一二区 | 成人嗯啊视频在线观看 | 一区二区在线免费观看 | 久久精品亚洲成在人线av网址 | avbobo官网| 国产精品区一区二区三 | jiucao视频在线观看 | 午夜精品亚洲 | 日韩免费电影 | 天天插天天舔 | 成人一级黄色大片 | 国产一区二区视频在线播放 | 欧美激情综合色综合啪啪五月 | 午夜视频在线免费观看 | 成人 日韩 | 日韩欧美在线观看 | 久久精品国产一区二区三区不卡 | 免费人成年短视频在线观看免费网站 | 国产精品污污视频 | 蜜桃精品导航 | 99热免费精品 | 澳门久久精品 | 久久大香香蕉国产免费网站 |