{"id":15293574,"url":"https://github.com/nsnick/trendview","last_synced_at":"2026-01-05T20:08:07.959Z","repository":{"id":56924540,"uuid":"90286267","full_name":"nsnick/TrendView","owner":"nsnick","description":"A view for iOS that allows data to be trended","archived":false,"fork":false,"pushed_at":"2017-06-15T21:47:25.000Z","size":338,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-05T16:39:56.123Z","etag":null,"topics":["chart","cocoapods","graph","ios","objective-c","pod","swift","swift3","time-series","trend"],"latest_commit_sha":null,"homepage":"","language":"Objective-C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/nsnick.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-05-04T16:40:19.000Z","updated_at":"2017-05-05T20:30:47.000Z","dependencies_parsed_at":"2022-08-21T05:20:28.354Z","dependency_job_id":null,"html_url":"https://github.com/nsnick/TrendView","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nsnick%2FTrendView","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nsnick%2FTrendView/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nsnick%2FTrendView/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nsnick%2FTrendView/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nsnick","download_url":"https://codeload.github.com/nsnick/TrendView/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245294769,"owners_count":20591909,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["chart","cocoapods","graph","ios","objective-c","pod","swift","swift3","time-series","trend"],"created_at":"2024-09-30T16:50:02.704Z","updated_at":"2026-01-05T20:08:07.892Z","avatar_url":"https://github.com/nsnick.png","language":"Objective-C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# TrendView\n\npod 'TrendView', '~\u003e 0.2'\n\n![Alt text](/screenshot.png?raw=true)\n\n[Objective-C example](https://github.com/nsnick/trendview-example-objc)\n\n[Swift example](https://github.com/nsnick/trendview-example-swift)\n\n## Swift \n``` swift\n\n    let dataArray1 = [0,1,3,5,6,8,7,6,5,4,2,2,0]\n    let dataArray2 = [9,8,6,5,4,3,2,2,4,6,8,9,9]\n    \n    let series1: NSMutableArray\n    let series2: NSMutableArray\n    let allSeries: NSMutableArray\n    \n    var trendView: TVTrendView?\n    \n\n    override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?) {\n        series1 = NSMutableArray()\n        series2 = NSMutableArray()\n        \n        for i:NSInteger in 0 ..\u003c dataArray1.count {\n            let point1:TVPoint = TVPoint.init(x: Double(i), andY:Double(dataArray1[i]))\n            series1.add(point1)\n            let point2:TVPoint = TVPoint.init(x: Double(i), andY:Double(dataArray2[i]))\n            series2.add(point2)\n        }\n        allSeries = [series1, series2]\n        super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil)\n    }\n    \n    required init?(coder aDecoder: NSCoder) {\n        fatalError(\"init(coder:) has not been implemented\")\n    }\n    \n\n\n    override func didReceiveMemoryWarning() {\n        super.didReceiveMemoryWarning()\n        // Dispose of any resources that can be recreated.\n    }\n    \n    override func viewDidLoad() {\n        super.viewDidLoad()\n\n        let trendViewFrame: CGRect = CGRect(x: 0, y: 20, width: self.view.frame.size.width, height: self.view.frame.size.width*2/3)\n        trendView = TVTrendView.init(frame: trendViewFrame, style: TVTrendViewStyleDefault)\n        trendView!.titleText = \"Trend Title\"\n        trendView!.xAxisLabelText = \"X Axis Label\"\n        trendView!.yAxisLabelText = \"Y Axis Label\"\n        trendView!.xUnits = \"X Units\"\n        trendView!.yUnits = \"Y Units\"\n        trendView!.datasource = self\n    \n        view.addSubview(trendView!)\n    }\n    \n    func numberOfSeries(in trendView:TVTrendView) -\u003e UInt {\n        return 2;\n    }\n    \n    func trendView(_ trendView:TVTrendView, numberOfElementsInSeries series:CLong) -\u003e UInt {\n        var smallestNumber:UInt = .max\n        for series in allSeries {\n            if (UInt((series as! NSArray).count) \u003c smallestNumber) {\n                smallestNumber = UInt((series as! NSArray).count);\n            }\n        }\n        return smallestNumber;\n    }\n    \n    func trendView(_ trendView:TVTrendView, pointInSeries seriesIndex:Int, for index:CLong) -\u003e TVPointProtocol {\n        let series:NSArray = allSeries[seriesIndex] as! NSArray\n        let point:TVPoint = series[index] as! TVPoint;\n        return point;\n    }\n    \n    /*\n     *  You must tell the trendview what range of values to display\n     */\n    func dataRanges(for trendView:TVTrendView)  -\u003e TVDataRanges{\n        let point:TVPoint = (allSeries[0] as! NSArray).object(at: 0) as! TVPoint;\n    \n        var minX = point.x\n        var minY = point.y\n        var maxX = point.x\n        var maxY = point.y\n    \n        for series in allSeries {\n            if let series:NSArray = series as? NSArray {\n                for point in (series as! NSMutableArray) {\n                    if let point:TVPoint = point as? TVPoint {\n                        if (point.x \u003c minX) {\n                            minX = point.x\n                        }\n                        if (point.y \u003c minY) {\n                            minY = point.y\n                        }\n                        if (point.x \u003e maxX) {\n                            maxX = point.x\n                        }\n                        if (point.y \u003e maxY) {\n                            maxY = point.y\n                        }\n                    }\n                }\n            }\n        }\n    \n        let ranges:TVDataRanges = trendView.dataRange(withMinX: minX, minY: minY, maxX: maxX, maxY: maxY)\n    \n        return ranges\n    }\n    \n    func trendView( _: TVTrendView, colorForSeries series:CLong) -\u003e UIColor {\n        if (series == 0) {\n            return UIColor.red\n    } else if (series == 1) {\n            return UIColor.blue\n    }\n        return UIColor.yellow\n    }\n\n```\n\n## Objective-C\n\nimplement the TVTrendViewDatasource protocol\n\n``` objective-c\n\n-(void)viewDidLoad {\n    [super viewDidLoad];\n    CGRect trendViewFrame = CGRectMake(0, 20, self.view.frame.size.width, self.view.frame.size.width*2/3);\n    trendView = [[TVTrendView alloc] initWithFrame:trendViewFrame];\n    trendView.titleText = @\"Trend Title\";\n    trendView.xAxisLabelText = @\"X Axis Label\";\n    trendView.yAxisLabelText = @\"Y Axis Label\";\n    trendView.xUnits = @\"X Units\";\n    trendView.yUnits = @\"Y Units\";\n    trendView.datasource = self;\n    \n    [self.view addSubview:trendView];\n}\n\n-(NSUInteger)numberOfSeriesInTrendView:(TVTrendView *)trendView {\n    return 2;\n}\n\n-(NSUInteger)trendView:(TVTrendView *)trendView numberOfElementsInSeries:(long)series {\n    NSUInteger smallestNumber = NSUIntegerMax;\n    for (NSArray *series in allSeries) {\n        if (series.count \u003c smallestNumber) {\n            smallestNumber = series.count;\n        }\n    }\n    return smallestNumber;\n}\n\n-(id\u003cTVPointProtocol\u003e)trendView:(TVTrendView *)trendView pointInSeries:(long)series forIndex:(long)index {\n    TVPoint *point = [(NSMutableArray *)allSeries[series] objectAtIndex:index];\n    return point;\n}\n\n/*\n *  You must tell the trendview what range of values to display\n */\n-(TVDataRanges)dataRangesForTrendView:(TVTrendView *)trendView {\n    TVPoint *point;\n    \n\n    point = [allSeries[0] objectAtIndex:0];\n    \n    double minX = point.x;\n    double minY = point.y;\n    double maxX = point.x;\n    double maxY = point.y;\n    \n    for (NSMutableArray *series in allSeries) {\n        for (TVPoint *point in series) {\n            \n            if (point.x \u003c minX) {\n                minX = point.x;\n            }\n            if (point.y \u003c minY) {\n                minY = point.y;\n            }\n            if (point.x \u003e maxX) {\n                maxX = point.x;\n            }\n            if (point.y \u003e maxY) {\n                maxY = point.y;\n            }\n        }\n    }\n    \n    TVDataRanges ranges = [trendView dataRangeWithMinX:minX minY:minY maxX:maxX maxY:maxY];\n    \n    return ranges;\n}\n\n-(UIColor *)trendView:(TVTrendView *)trendView colorForSeries:(long)series {\n    if (series == 0) {\n        return [UIColor redColor];\n    } else if (series == 1) {\n        return [UIColor blueColor];\n    } \n    return [UIColor yellowColor]; \n}\n\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnsnick%2Ftrendview","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnsnick%2Ftrendview","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnsnick%2Ftrendview/lists"}