iOS 利用chart.min.js画表格(其实是iOS与javascript和html的结合)

本文介绍了如何在iOS应用中结合UIWebView和javascript的chart.min.js库来展示图表。通过创建HTML页面并利用javascript画图,然后在iOS中加载和执行javascript代码,实现了将数据以图表形式展示在app界面上。
摘要由CSDN通过智能技术生成

最近在做一个基于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;

//生产model实例的方法

- (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;

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值