Skip to content

Commit

Permalink
upadte readme
Browse files Browse the repository at this point in the history
  • Loading branch information
ZhipingYang committed Aug 11, 2019
1 parent d04ab7f commit e36e17f
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 35 deletions.
2 changes: 1 addition & 1 deletion Demo/XYChart/view/ChartViewCell.m
Expand Up @@ -26,7 +26,7 @@ - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSStr
if (self) {
XYChartType type = [reuseIdentifier isEqualToString:lineChartReuseIdentifier]
? XYChartTypeLine : XYChartTypeBar;
_chartView = [[XYChart alloc] initWithFrame:CGRectZero chartType:type];
_chartView = [[XYChart alloc] initWithFrame:CGRectZero type:type];
_chartView.delegate = self;
[self.contentView addSubview:_chartView];
}
Expand Down
117 changes: 88 additions & 29 deletions README.md
Expand Up @@ -25,38 +25,57 @@
|:-------:|:---------:|
| ![WechatIMG65](https://user-images.githubusercontent.com/9360037/62707044-4671de00-ba23-11e9-9ddc-57509edba0dc.jpeg) | ![WechatIMG66](https://user-images.githubusercontent.com/9360037/62707048-47a30b00-ba23-11e9-90a9-c414a92da2cc.jpeg) |
| single datas in linechart | single datas in linechart |
| ![WechatIMG67](https://user-images.githubusercontent.com/9360037/62707045-470a7480-ba23-11e9-87c9-25d8b8df1d7b.jpeg) | ![WechatIMG68](https://user-images.githubusercontent.com/9360037/62707047-470a7480-ba23-11e9-9ea1-687185c04f74.jpeg) |
| mutiple datas in linechart | mutiple datas in linechart |
| ![WechatIMG70](https://user-images.githubusercontent.com/9360037/62711726-20047080-ba2c-11e9-8890-022fe4e58df9.jpeg) | ![click](https://user-images.githubusercontent.com/9360037/62712419-5ee6f600-ba2d-11e9-9605-aeaba3097e9b.gif) |
| **LineDotsClicked:** show all if the dots closed | **BarClicked:** custom click effects |
| **LineDotsClicked:** show all if the dots closed in multi-datas | **BarClicked:** custom click effects in multi-datas |
| ![gif](https://user-images.githubusercontent.com/9360037/62709107-54c1f900-ba27-11e9-8312-8fcec88a58d5.gif) | ![gif](https://user-images.githubusercontent.com/9360037/62709087-48d63700-ba27-11e9-86f3-e92e4e1bd094.gif) |
| scrolling linechart (did set row width) | scrolling barchart (did set row width) |


### Install
## Install

> required `iOS >= 8.0` with [Cocoapods](https://cocoapods.org/)
>
> ```ruby
> pod 'XYChart'
> ```
```ruby
pod 'XYChart'
```
## Using

### Usage
<details><summary> Expand for XYChart details </summary>

```objective-c
@interface XYChart : UIView<XYChartContainer>
@interface XYChart : UIView<XYChartReload>

@property (nonatomic, weak, nullable) id<XYChartDataSource> dataSource;
@property (nonatomic, weak, nullable) id<XYChartDelegate> delegate;

@property (nonatomic, readonly) XYChartType chartType;

- (instancetype)initWithFrame:(CGRect)frame chartType:(XYChartType)chartType NS_DESIGNATED_INITIALIZER;
- (instancetype)initWithFrame:(CGRect)frame type:(XYChartType)type NS_DESIGNATED_INITIALIZER;
- (instancetype)initWithType:(XYChartType)type;

/**
更新图标数据

@param dataSource 数据
@param animation 是否执行动画
*/
- (void)setDataSource:(id<XYChartDataSource>)dataSource animation:(BOOL)animation;

/**
重载数据

@param animation 是否执行动画
*/
- (void)reloadData:(BOOL)animation;

@end
```
方法1:
</details>
**Method 1:**
```objective-c
_chartView = [[XYChart alloc] initWithFrame:CGRectMake(0, 0, 300, 100) chartType:XYChartTypeLine];
Expand All @@ -65,65 +84,105 @@ _chartView.delegate = self;
[self.view addSubview:_chartView];
```

方法2:
**Method 2:**

```objective-c
// ChartGroup is the child of XYChartDataSourceItem
_datasource = [[ChartGroup alloc] initWithStyle:XYChartTypeBar section:2 row:15 width:60];
// the obj follow the XYChartDataSource protocol
_datasource = [[XYChartDataSourceItem alloc] init];

_chartView = [[XYChart alloc] initWithFrame:CGRectMake(0, 0, 300, 100)
chartType:XYChartTypeLine];
_chartView = [[XYChart alloc] initWithType:XYChartTypeLine];
_chartView.dataSource = _datasource;
[self.view addSubview:_chartView];
```
### XYChartDataSource
<details><summary> Expand for XYChartDataSource protocol details </summary>
```objective-c
/**
多套对比数据展示
*/
@protocol XYChartDataSource
// 多少条并行对比数据,折线图表现多条线,柱状图表现一列中有几条柱状图
/**
多少条并行对比数据,折线图表现多条线,柱状图表现一列中有几条柱状图
*/
- (NSUInteger)numberOfSectionsInChart:(XYChart *)chart;
// 完整的周期内,数据的个数,横向列数
/**
完整的周期内,数据的个数,横向列数
*/
- (NSUInteger)numberOfRowsInChart:(XYChart *)chart;
// x坐标的标题
/**
x坐标的标题
*/
- (NSAttributedString *)chart:(XYChart *)chart titleOfRowAtIndex:(NSUInteger)index;
// y坐标的标题
/**
x坐标的标题
*/
- (NSAttributedString *)chart:(XYChart *)chart titleOfSectionAtValue:(CGFloat)sectionValue;
// index下的数据模型
/**
index下的数据模型
*/
- (id<XYChartItem>)chart:(XYChart *)chart itemOfIndex:(NSIndexPath *)index;
// 标记y轴方向高亮区间
/**
标记y轴方向高亮区间
*/
- (XYRange)visibleRangeInChart:(XYChart *)chart;
// y轴方向分段,5就分5段
/**
y轴方向分段,5就分5段
*/
- (NSUInteger)numberOfLevelInChart:(XYChart *)chart;
// 横向一栏的宽度
/**
横向一栏的宽度
*/
- (CGFloat)rowWidthOfChart:(XYChart *)chart;
// 自适应平均分横向栏目的宽度
/**
自适应平均分横向栏目的宽度
*/
- (BOOL)autoSizingRowInChart:(XYChart *)chart;
@end
```
</details>

### XYChartDelegate

<details><summary> Expand for <bold>XYChartDelegate</bold> protocol details </summary>

```objective-c
@protocol XYChartDelegate
@optional

/**
是否展示UIMenuController
*/
- (BOOL)chart:(XYChart *)chart shouldShowMenu:(NSIndexPath *)index;

/**
点击后的action,重载一般就不show UIMenuController了
*/
- (void)chart:(XYChart *)chart itemDidClick:(id<XYChartItem>)item;

/**
line用于展示圆圈,bar用于柱形图的动画
*/
- (CAAnimation *)chart:(XYChart *)chart clickAnimationOfIndex:(NSIndexPath *)index;

@end
```
</details>
## Author
XcodeYang, xcodeyang@gmail.com
## License
XYChart is available under the MIT license. See the LICENSE file for more info.
3 changes: 2 additions & 1 deletion XYChart/XYChart.h
Expand Up @@ -20,7 +20,8 @@ NS_ASSUME_NONNULL_BEGIN

@property (nonatomic, readonly) XYChartType type;

- (instancetype)initWithFrame:(CGRect)frame chartType:(XYChartType)chartType NS_DESIGNATED_INITIALIZER;
- (instancetype)initWithFrame:(CGRect)frame type:(XYChartType)type NS_DESIGNATED_INITIALIZER;
- (instancetype)initWithType:(XYChartType)type;

/**
更新图标数据
Expand Down
13 changes: 9 additions & 4 deletions XYChart/XYChart.m
Expand Up @@ -29,26 +29,31 @@ @interface XYChart ()

@implementation XYChart

- (id)initWithFrame:(CGRect)frame chartType:(XYChartType)chartType
- (id)initWithFrame:(CGRect)frame type:(XYChartType)type
{
self = [super initWithFrame:frame];
if (self) {
self.sectionLabels = @[].mutableCopy;
_horizonLines = @[].mutableCopy;
_type = chartType;
_type = type;
[self setUpChartElements];
}
return self;
}

- (instancetype)initWithType:(XYChartType)type
{
return [self initWithFrame:CGRectZero type:type];
}

- (instancetype)initWithCoder:(NSCoder *)aDecoder
{
return [self initWithFrame:CGRectZero chartType:XYChartTypeLine];
return [self initWithFrame:CGRectZero type:XYChartTypeLine];
}

- (instancetype)initWithFrame:(CGRect)frame
{
return [self initWithFrame:frame chartType:XYChartTypeLine];
return [self initWithFrame:frame type:XYChartTypeLine];
}

- (void)setUpChartElements
Expand Down

0 comments on commit e36e17f

Please sign in to comment.