最近在做一个基于genecard的iOS app,其中要把数据以图表的形式展现出来,所以在网上学习了一下用UIWebView的用法,用javascript在html页面上画好图再展现在app界面上。
当然我不会每一样图都演示一遍,我只演示一种图形,好了,贴代码。
1.首先肯定是要准备一个html页面让javascript在上面画图啰。
<!doctype html>
<html>
<head>
<title></title>
<metaname = "viewport" content ="initial-scale = 1, user-scalable = no">
<style>
</style>
</head>
<bodystyle="background-color: transparent;">
//待会就在这里画图
<canvas></canvas><br/>
<a id="callback"href="callback:whatever"></a>
<script src="chart.min.js"></script>
</body>
</html>
2.看.js文件,看看画每一种图形所要的数据是什么,然后写一个个model,但我们可以抽取每种图形所要的数据,生产一个父类再让其他的去继承他(但我们这就不那么细了)。
//
// TWRDataSet.h
// HILab1.0
//
// Created by dengwt on 2017/2/10.
// Copyright © 2017年 dengwt. All rights reserved.
//
#import <Foundation/Foundation.h>
#import "TWRChart.h"
#import <UIKit/UIKit.h>
@interface TWRDataSet : NSObject
@property (strong,nonatomic) UIColor *fillColor;
@property (strong,nonatomic) UIColor *strokeColor;
@property (strong,nonatomic) UIColor *pointColor;
@property (strong,nonatomic) UIColor *pointStrokeColor;
@property (copy,nonatomic) NSMutableArray *dataPoints;
- (instancetype)initWithDataPoints:(NSArray *)dataPoints
fillColor:(UIColor *)fillColor
strokeColor:(UIColor *)strokeColor
pointColor:(UIColor *)pointColor
pointStrokeColor:(UIColor *)pointStrokeColor;
- (instancetype)initWithDataPoints:(NSArray *)dataPoints
fillColor:(UIColor *)fillColor
strokeColor:(UIColor *)strokeColor;
- (instancetype)initWithDataPoints:(NSArray *)dataPoints;