Git Product home page Git Product logo

charts's Introduction

Version 4.0.0, synced to MPAndroidChart #f6a398b

alt tag Supported Platforms Releases Latest pod release Carthage compatible Build Status codecov Join the chat at https://gitter.im/danielgindi/Charts

Just a heads up: Charts 5.0 has some breaking changes. Charts has now been renamed DGCharts to prevent conflicts with Apple's new Swift Charts. Please read the release/migration notes.

One more heads up: As Swift evolves, if you are not using the latest Swift compiler, you shouldn't check out the master branch. Instead, you should go to the release page and pick up whatever suits you.

  • Xcode 14 / Swift 5.7 (master branch)
  • iOS >= 12.0 (Use as an Embedded Framework)
  • tvOS >= 12.0
  • macOS >= 10.13

Okay so there's this beautiful library called MPAndroidChart by Philipp Jahoda which has become very popular amongst Android developers, but there was no decent solution to create charts for iOS.

I've chosen to write it in Swift as it can be highly optimized by the compiler, and can be used in both Swift and ObjC project. The demo project is written in ObjC to demonstrate how it works.

An amazing feature of this library now, for Android, iOS, tvOS and macOS, is the time it saves you when developing for both platforms, as the learning curve is singleton- it happens only once, and the code stays very similar so developers don't have to go around and re-invent the app to produce the same output with a different library. (And that's not even considering the fact that there's not really another good choice out there currently...)

Having trouble running the demo?

  • ChartsDemo/ChartsDemo.xcodeproj is the demo project for iOS/tvOS
  • ChartsDemo-OSX/ChartsDemo-OSX.xcodeproj is the demo project for macOS
  • Make sure you are running a supported version of Xcode.
    • Usually it is specified here a few lines above.
    • In most cases it will be the latest Xcode version.
  • Make sure that your project supports Swift 5.0
  • Optional: Run carthage checkout in the project folder, to fetch dependencies (i.e testing dependencies).
    • If you don't have Carthage - you can get it here.

Usage

In order to correctly compile:

  1. Drag the DGCharts.xcodeproj to your project
  2. Go to your target's settings, hit the "+" under the "Frameworks, Libraries, and Embedded Content" section, and select the DGCharts.framework
  3. @import DGCharts
  4. When using Swift in an ObjC project:
  • You need to import your Bridging Header. Usually it is "YourProject-Swift.h", so in ChartsDemo it's "ChartsDemo-Swift.h". Do not try to actually include "ChartsDemo-Swift.h" in your project :-)
  • (Xcode 8.1 and earlier) Under "Build Options", mark "Embedded Content Contains Swift Code"
  • (Xcode 8.2+) Under "Build Options", mark "Always Embed Swift Standard Libraries"
  1. When using Realm.io:
    • Note that the Realm framework is not linked with Charts - it is only there for optional bindings. Which means that you need to have the framework in your project, and in a compatible version to whatever is compiled with DGCharts. We will do our best to always compile against the latest version.
    • You'll need to add ChartsRealm as a dependency too.

3rd party tutorials

Video tutorials

Blog posts

Want your tutorial to show here? Create a PR!

Troubleshooting

Can't compile?

  • Please note the difference between installing a compiled framework from CocoaPods or Carthage, and copying the source code.
  • Please read the Usage section again.
  • Search in the issues
  • Try to politely ask in the issues section

Other problems / feature requests

  • Search in the issues
  • Try to politely ask in the issues section

CocoaPods Install

Add pod 'DGCharts' to your Podfile. "DGCharts" is the name of the library.
For Realm support, please add pod 'ChartsRealm' too.

Note: pod 'ios-charts' is not the correct library, and refers to a different project by someone else.

Carthage Install

DGCharts now include Carthage prebuilt binaries.

github "danielgindi/Charts" == 5.1.0
github "danielgindi/Charts" ~> 5.1.0

In order to build the binaries for a new release, use carthage build --no-skip-current && carthage archive Charts.

Swift Package Manager Install

Swift Package Manager

dependencies: [
    .package(url: "https://github.com/danielgindi/Charts.git", .upToNextMajor(from: "5.1.0"))
]

3rd party bindings

Xamarin (by @Flash3001): iOS - GitHub/NuGet. Android - GitHub/NuGet.

Help

If you like what you see here, and want to support the work being done in this repository, you could:

  • Contribute code, issues and pull requests
  • Let people know this library exists (:fire: spread the word :fire:)
  • Donate (You can buy me a beer, or you can buy me dinner :-)

Note: The author of MPAndroidChart is the reason that this library exists, and is accepting donations on his page. He deserves them!

Questions & Issues

If you are having questions or problems, you should:

  • Make sure you are using the latest version of the library. Check the release-section.
  • Study the Android version's Documentation-Wiki
  • Search or open questions on stackoverflow with the ios-charts tag
  • Search known issues for your problem (open and closed)
  • Create new issues (please 🔥 search known issues before 🔥, do not create duplicate issues)

Features

Core features:

  • 8 different chart types
  • Scaling on both axes (with touch-gesture, axes separately or pinch-zoom)
  • Dragging / Panning (with touch-gesture)
  • Combined-Charts (line-, bar-, scatter-, candle-stick-, bubble-)
  • Dual (separate) Axes
  • Customizable Axes (both x- and y-axis)
  • Highlighting values (with customizable popup-views)
  • Save chart to camera-roll / export to PNG/JPEG
  • Predefined color templates
  • Legends (generated automatically, customizable)
  • Animations (build up animations, on both x- and y-axis)
  • Limit lines (providing additional information, maximums, ...)
  • Fully customizable (paints, typefaces, legends, colors, background, gestures, dashed lines, ...)
  • Plotting data directly from Realm.io mobile database (here)

Chart types:

Screenshots are currently taken from the original repository, as they render exactly the same :-)

  • LineChart (with legend, simple design) alt tag

  • LineChart (with legend, simple design) alt tag

  • LineChart (cubic lines) alt tag

  • LineChart (gradient fill) alt tag

  • Combined-Chart (bar- and linechart in this case) alt tag

  • BarChart (with legend, simple design)

alt tag

  • BarChart (grouped DataSets)

alt tag

  • Horizontal-BarChart

alt tag

  • PieChart (with selection, ...)

alt tag

  • ScatterChart (with squares, triangles, circles, ... and more)

alt tag

  • CandleStickChart (for financial data)

alt tag

  • BubbleChart (area covered by bubbles indicates the value)

alt tag

  • RadarChart (spider web chart)

alt tag

Documentation

Currently there's no need for documentation for the iOS/tvOS/macOS version, as the API is 95% the same as on Android.
You can read the official MPAndroidChart documentation here: Wiki

Or you can see the Charts Demo project in both Objective-C and Swift (ChartsDemo-iOS, as well as macOS ChartsDemo-macOS) and learn the how-tos from it.

Special Thanks

Goes to @liuxuan30, @petester42 and @AlBirdie for new features, bugfixes, and lots and lots of involvement in our open-sourced community! You guys are a huge help to all of those coming here with questions and issues, and I couldn't respond to all of those without you.

Our amazing sponsors

Debricked: Use open source securely

debricked

License

Copyright 2016 Daniel Cohen Gindi & Philipp Jahoda

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

charts's People

Contributors

aelam avatar albertdonaire avatar antimoron avatar antonthedev avatar danielgindi avatar felixherrmann avatar icecrystal23 avatar jjatie avatar kcome avatar kemchenj avatar krbarnes avatar lcsmarcal avatar liuxuan30 avatar mathewa6 avatar mconintet avatar mkubenka avatar mpz-financial-com avatar philjay avatar pixelspark avatar pmairoldi avatar potato04 avatar rynecheow avatar sumosimo avatar svenmuc avatar thierryh91200 avatar valeriyvan avatar vincentsit avatar wjacker avatar wlxo0401 avatar zntfdr avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

charts's Issues

Unable to hide Y values

I am implementing a Pie chart and I am unable to hide Y values.
I tried setting dataSet.drawValuesEnabled = NO but this hid both X and Y labels.
On the contrary I am able to hide X labels by [_chartView setDrawSliceTextEnabled:NO]

xcode complains ChartsDemo-Swift.h can't be found

When I try to build ChartsDemo, Xcode complains about ChartsDemo-Swift.h not being found in a few .m files whicj have #import "ChartsDemo-Swift.h" in them.

I can't find the file anywhere in the project as well.

Charts won't draw unless initialized with a frame

It took me a while to figure this out, but I couldn't get the charts to draw unless the chart view was initialized with a frame.

There would be two solutions to this, either support changing the frame of the view or do something drastically like putting a fatalError() in the init() method, to prevent using that.

var lineChart = LineChartView() // won't draw any chart
var lineChart = LineChartView(frame: view.bounds) // will draw charts with the specified frame

I might write a pull request with a fix, but at least it is reported now.

Best,
Simon

PieChart chartValueSelected don't return the good entry

Hello,

on the function for Pie chart
-(void)chartValueSelected:(ChartViewBase * __nonnull)chartView entry:(ChartDataEntry * __nonnull)entry dataSetIndex:(NSInteger)dataSetIndex highlight:(ChartHighlight * __nonnull)highlight

the entry is not good and dataSetIndex is set to 0

could you explained me what i must do for getting the good entry?

Have a good day

Amandine

Library not loaded: @rpath/Charts.framework/Charts Xcode 6.3.1, iOS 8.3

Simulator Works fine but when running on an iPhone I get this error.
Xcode 6.3.1 and iOS 8.3 Deployment.
Any help?

dyld: Library not loaded: @rpath/Charts.framework/Charts
Referenced from: /private/var/mobile/Containers/Bundle/Application/F1F8EA37-A2F3-4078-8F65-9291C708B698/stepz.app/stepz
Reason: image not found
(lldb)

i am getting this issue?

var value = BarChartDataEntry(values: self.smImg[i], xIndex: i) 

error: Use of unresolved identifier 'smimg'

pod not support iOS 7.0 ???

s.ios.deployment_target = "8.0"

[!] The platform of the target Pods (iOS 7.0) is not compatible with Charts (2.0.9) which has a minimum requirement of iOS 8.0.

Named axis support?

2015-04-19 00-48-45 lifts rimmer sk last -1

Looked at android wiki, but did not find the possibility to name x or y axis.

Is that possible?

When I used iOS-charts in iOS 7 project

I dragged all of .swift files into my project, then build the project, 400+ errors appeared, it seemed like the codes can't recognize UIKit, I had to add a line import UIKit manually in every .swift file.
Is there anything wrong in my steps?
BTW: This charts library is really powerful!

hi can this demo be done under one .xcodeproj

when i open charts demo.xcodeproj in Xcode it consist of charts.xcodeproj.is it possible to directly take .swift files from charts and implement in charts demo project with out importing whole charts.xcodeproj

Two graphs overlaying each other

Hi, may I know is there are way for me to overlay line graph above a candle stick graph with synchronise xy axis. I tried to put the same values to each graphs and positioned them starts from zero but the axis are not tally (you can see the candlestick 185 is lower than line graph's 180 y-axis.

Thanks

ios simulator screen shot 22 apr 2015 1 26 14 pm

Command failed due to signal: Segmentation fault: 11

Hi,

Firstly great initiative. I've been looking for a good charting library for sometime now. Highly appreciated. I tried testing this today and getting the above error. I'm trying this in Xcode Version 6.3 (6D520o).

It is happening at two files in the library. I'm posting the final error message for both of them

While emitting IR SIL function @_TFC6Charts21CombinedChartRenderer15createRenderersfS0_FT_T_ for 'createRenderers' at /ios-charts/Charts/Classes/Renderers/CombinedChartRenderer.swift:50:14

While emitting IR SIL function @_TFC6Charts19ChartLegendRenderer12renderLegendfS0_FT7contextCSo9CGContext6legendGSQCS_11ChartLegend__T_ for 'renderLegend' at /ios-charts/Charts/Classes/Renderers/ChartLegendRenderer.swift:104:12

Can you let me know how to get rid of those ?

Tried :

  1. When I comment out the switch cases in the respective functions (createRenderers, renderLegend) it compiles fine. Although I hardly think it's a solution.

Core Data interfacing?

This looks great. Is there support for interfacing with core data such that not all data needs to be pushed into the chart but can be pulled as needed?

Perhaps you could point me to the proper API.

Thanks!

Is there any inertia effect in the library?

When I drag line chart from left to right, the animation seems so angular, I wonder is there a inertia effect in the chart, just makes the dragging animation more smooth.
Thanks! Waiting for reply.

Can't import "module-swift.h"

I try to import to one project (teste). When I build the "#import teste-Swift.h" can't be found, resulting in the "Cannot find protocol declaration for 'ChartViewDelegate'. What I'm doing wrong?

X axis names visibility (Rotation)

Hello there,

Am plotting 6 dates on x axis with format "dd/MM/yy" but the font size of each label doesn't auto shrink and it looks bad. Can i show these values rotated by 45 degrees or is anything similar to text autoshrink.

If not these 2 features will be good for enhancements

Thanks,
Adam

piechart - yOffset

Hello
i would like to thank you for open sourcing this beast of a library. You have made our lives a lot easier.
Now my question is regarding the yOffset of the legend for the pie charts.
I am showing the legend on the center of the pie chart and i am using yOffset as well.
As i can see in the chartlegendrendered the yOffset is not taken into account when the legend's position is PiechartCenter.
so should this:
var posY = (viewPortHandler.chartHeight / 2.0 - _legend.neededHeight / 2.0);
be replaced with this:
var posY = (viewPortHandler.chartHeight / 2.0 - _legend.neededHeight / 2.0) + (_legend.yOffset);

i would appreciate your help on this
thanks

Pinch zoom release triggers pan

When you zoom in on a chart using a pinch gesture, the charts are sometimes being panned to a different position once the pinch gesture has ended.
You can, for instance, check the CandleStickChart in your demo project. Other chart types show this as well, though.

357 Compile Errors on framework files

I compiled it with xcode 6.2 and 6.3 beta 4 and got 357 errors mostly from every time you call "as!"

Before I go through and manually fix all the syntax errors, I just wanted to double check with you that I'm not missing a step..

Carthage support

Hi @danielgindi

Nice project! I was wondering if you would be willing to support Carthage. All that's needed to support it is setup your Charts.framework scheme to be shared. I've created a pull request in case you're interested.

Unknown class LineChartView in Interface Builder file

I alwas get this runtime error when switching to the viewcontroller where the LineChartView is placed.
As proposed in this case of error I added "-all_load -ObjC" to the "Other Linker Flags" in project and targets settings, but this error still comes up. Any hint?

LineChart Axis Inset?

Hi, thanks for the great library! Is it possible to add an inner padding to x axes as shown in the picture below?

graph padding

I.e., both the first and last points and xAxis labels are inset by ~15px. Would be super useful. Thanks!

Drawing CubicLineChart based on NSDates

Hi there,

first of all - thanks for providing this framework. It's exactly what I've been looking for for years.

A problem I am currently facing is that the cubic line charts in my app are currently drawn based on the amount of values in the Set/Array (i.e. if there are 5 values to draw in a rect which is 200px wide, the x-distance between the graph points is 40px).
However, in many use cases, drawing the chart based on NSDates makes a lot of sense. If you for example think about stock prices: a specific stock price is always associated to a specific date & time.

Maybe I've just overseen this option.
Can this already be done with ios-charts? If not, are there plans to implement this option?

swift demo...

Thanks for the port.

Any way to get a swift demo?

Thanks again!

Changing the specific data point (circle color) in Line Chart

In case of Line Chart, whenever user is tapping on the small circle(data point), a Popover is displaying to user and i want to change the color of this specific data point(small circle only) instead of color of whole line chart.

Is there any way to do this ?

Import with Swift(not objc) not working

Hi

I am trying to build a very simple code using swift.
But I can't figure out how can I import the Classes.

When I set the view to be PieChartView and create a :
@IBOutlet weak var testView: PieChartView!

I got "use of undeclared type: PieChartView

I did try to import PieChartView, but xcode can't find it.

I am using Xcode 6.3 beta 4 and already setup the "Embedded Binaries" and "Linked Frameworks and Libraries" to the Charts.framework.

Also I can't find one sample code of swift on the web.

Thanks

Cocoapod

Hi,

Can you tell me why this project is not in the CocoaPod spec?

Last item's visibility issue when zooming

Hello. Am using the LineChartView and i have noticed that while zooming (pinch) the last value of the line is not shown. You can't even scroll to that value. What i do is am pinch zooming in and at a certain level of zooming i cant scroll to the last item value. The value is not visible in the screen except the line going to that value.

Additionally, can i draw the line skipping the first and the last value as a result my line will not touching charts edges?

CandleChartData isn't combinable with other data types

In a CombinedChart you can't combine CandleChartData with other data types.
Add for example BarChartData or LineChartData to it and the candle stick chart won't get rendered.

Nevermind, that was an issue on my side!

UISwipeGestureRecognizer

How can I use UISwipeGestureRecognizer on chartView? I wrote some code but it didn't work.

  • (void)viewDidLoad
    {
    UISwipeGestureRecognizer *swipeRight = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(slideToRightWithGestureRecognizer:)];
    swipeRight.direction = UISwipeGestureRecognizerDirectionRight;

    [_chartView addGestureRecognizer:swipeRight];
    }

-(void)slideToRightWithGestureRecognizer:(UISwipeGestureRecognizer *)gestureRecognizer{
NSLog(@"here");
}

Performance Enhancements

Are there any plans to enhance the performance of the library in a way Philip did with MPAndroidCharts?
With his enhancements it is now possible to render thousands of data points smoothly on Android.
I've had a quick glance at the ios-charts implementation and from what I've seen it is based on the original MPAndroidCharts implementation without the latest performance enhancements.

Having it render thousands of points as well would be HUGE plus for the library as it would effectively render all commercial versions useless (most of which are a waste of time and money anyways).

A lot of compile errors.

I compile with Xcode 6.2, and there are a lot of errors. like:

  1. @objc is only available for class type.
  2. as! should be as.

for me, these look like the code is written in old swift(it changes a lot).

dyld_fatal_error

Xcode 6.3 and iOS 8.3 Deployment.
Any help?

dyld: Library not loaded: @rpath/libswiftCore.dylib
Referenced from: /private/var/mobile/Containers/Bundle/Application/37604CDA-D682-424D-A215-8FC42D486884/PatientApp.app/Frameworks/Charts.framework/Charts
Reason: image not found
(lldb)

screen shot 2015-04-30 at 1 43 59 pm
screen shot 2015-04-30 at 1 44 19 pm

demo crashes, and no swift examples?

When running your ChartsDemo app. I'm presented with the following errors:

dyld: Library not loaded: @rpath/Charts.framework/Charts
Referenced from: /private/var/mobile/Containers/Bundle/Application/9F8BD568-2130-48D8-9F62-E123EB2451BA/ChartsDemo.app/ChartsDemo
Reason: image not found
(lldb)

It's also written in Obj-c and not swift. Making it very difficult to translate for developers who havn't learned Obj-C to figure out how you're supposed to implement these charts?

Skip first and last value

Hello am using a LineChartView. Can i draw the line skipping the first and the last value as a result my line will not touching charts edges?

ChartsDemo-swift.h file not found

I have faced problem which describe by ( ChartsDemo-swift.h file not found ) i want to focused that everything is working correctly only this file isn't imported .

screen shot 2015-04-15 at 2 09 26 pm

Use of undeclared type 'CGFloat'

Has anyone had any luck getting this to compile for an iOS 7 project? I tried the suggested approach (copying all .swift files to your project), but I'm getting lots of compiler errors from what look to be missing UIKit imports:

ios-charts/Charts/Classes/Data/ScatterChartData.swift:19:43: Use of undeclared type 'CGFloat'; did you mean to use 'CGFloat'?
ios-charts/Charts/Classes/Data/ScatterChartData.swift:21:19: Use of unresolved identifier 'CGFloat'
ios-charts/Charts/Classes/Data/BarChartData.swift:18:31: Use of unresolved identifier 'CGFloat'
ios-charts/Charts/Classes/Data/BarChartData.swift:21:28: Use of undeclared type 'CGFloat'; did you mean to use 'CGFloat'?

Any idea what's going wrong? I'm using Xcode 6.3.1.

Charts/Charts.h file not found

Everytime I try to archive in Ad Hoc mode, it gives me this error. I added this as an embedded framework. I tried to mirror the ChartDemo settings as much as possible. Does anyone else get this and if so, how did you resolve this.

Thx in advance.

i want develop charts in swift?

i am using ur frame work for developing but i can't identify how to start ? i am new to iOS and swift please help me is there any sample in swift for your charts

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.