Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a gradient line chart #649

Closed
wants to merge 7 commits into from
Closed

Add a gradient line chart #649

wants to merge 7 commits into from

Conversation

Regno
Copy link

@Regno Regno commented Jan 5, 2016

For #537
Add functionality to draw a gradient line for line chart. It use exist property "colors" and new property "gradientPositions" for rendering gradient line.
Add two new public properties: "gradientPositions" and "drawGradientEnabled" for LineChartDataSet.
Add two new private functions: "drawGradientLine" and "generatePath" for LineChartRenderer

Example of usage:

override func viewDidLoad() {
        super.viewDidLoad()
        //set x values
        let count = 10
        var xVals: [String]! = []
        for (var i = 0; i < count; i++)
            {
                xVals.append("\(i)")
            }
        //set y values
        let range = 5.0
        var yVals: [ChartDataEntry] = []
        for (var i = 0; i < count; i++)
            {
                let val = drand48() * range + 35
                yVals.append(ChartDataEntry(value: val, xIndex: i))
            }
        let set1 = LineChartDataSet(yVals: yVals, label: "DataSet 1")
        //Set gradient
        set1.drawCubicEnabled = true
        set1.drawGradientEnabled = true
        chartView.drawGridBackgroundEnabled = false
        //set1.drawFilledEnabled = true
        set1.lineWidth = 2.0
        set1.circleRadius = 2.0
        set1.colors = [UIColor(red: 0.192, green: 0.686, blue: 0.980, alpha: 1.00), UIColor(red: 0.212, green: 0.863, blue: 0.318, alpha: 1.00), UIColor(red: 0.996, green: 0.867, blue: 0.275, alpha: 1.00), UIColor(red: 0.980, green: 0.090, blue: 0.157, alpha: 1.00)]
        set1.gradientPositions = [35.0, 36.6, 38.0, 40.0]
        // set Data
        var dataSets: [LineChartDataSet] = []
        dataSets.append(set1)
        let chartData = LineChartData(xVals: xVals, dataSets: dataSets)
        chartView.data = chartData
}

Result:
2016-01-05 15 11 11

@pmairoldi
Copy link
Collaborator

cool! there are conflicts with master could you rebase to fix those?

@maciejtrybilo
Copy link
Contributor

It's precisely what I need. Could I help at all moving this PR forward?

@liuxuan30
Copy link
Member

awesome!

@nehayward
Copy link

Any update on when this will get merged?

@danielgindi
Copy link
Collaborator

When it will be ready for merging.
Right now it is marked with "code styling problems", and it is already too far behind (merge conflicts).
When this PR will be ready, we'll need to implement the Android counterpart, but let's get at it one step at a time

@tnmendes
Copy link

tnmendes commented Dec 3, 2016

Hi, any update about this feature? thank you

@NeelAppsplanet
Copy link

NeelAppsplanet commented Apr 19, 2017

hi @Regno nice work , any update about this feature from your side? currently i'm working on swift 3.1 and getting some issues while migrating code from swift 2.1 , It would b great if you help me. Have u migrated this code repo in swift 3.1 ? thanks in advance!!!!!!!

@Kalvin126
Copy link

Any update on this? Would be nice to pull into main repo

@mdnjustin
Copy link

This is what I've been looking for. Would love for it to make it into the main branch.

@robin-garnham
Copy link

Will this also work for fixed stop colours?
I'm trying to implement a line chart that is differently coloured based on Y position.
E.g. gray at 0 -> 34.99, green at 35.00 -> 49.99, etc

@NallapatiMalleswari
Copy link

How to draw Gradient line based on width like in bellow image,but not based on x-axis ,y-axis based.
screen shot 2017-10-28 at 6 27 05 pm

@liuxuan30
Copy link
Member

seems not updated to swift 4. @danielgindi This feature has been asked a lot. Shall we go ahead without android support? I think we need a plan for new features that does not sync between iOS and android. waiting for the other one seems will take too long

@gunesmert
Copy link

Hey @liuxuan30 & @danielgindi . Is there any estimated time of merging this PR?

@dhaneshgosai
Copy link

Hey @danielgindi @liuxuan30

Any update when can we expect this feature on master branch ?

Thanks!

@jlubeck
Copy link

jlubeck commented Dec 18, 2017

Almost 2 years since this very nice pull request. Just wondering, is anyone workin on fixing the merge conflicts?
Thanks!

@pmairoldi
Copy link
Collaborator

I started looking at gradient stuff a while back and haven’t had to time to look through the code and merge/close all issues related to it.

From what I remember the timing of this pull request was not ideal since it was in the middle of the refactor from charts v2 to v3. That is why it has taken more time for it to make it in since basically all the code would have to be rewritten in the v3 style.

@liuxuan30
Copy link
Member

liuxuan30 commented Dec 19, 2017

There are several projects on github page created and now ongoing as high priority, and this is one of them. I think once we finish the 'more swift' project, we will focus on gradient and the named axis.
@petester42 I have categorized the PRs of swift refactoring here https://github.com/danielgindi/Charts/projects/4

@AndreaMiotto
Copy link

Can you merge this pull request?

@jjatie
Copy link
Collaborator

jjatie commented Dec 27, 2017

First there needs to be no merge conflicts. @liuxuan30, I think other features can be added while the "More Swift" project is ongoing. If there are any PRs you're uncertain match the Swift-ier style, feel free to tag me. If this is the gradient implementation we are going to go with, we should prioritize it.

I think we have an issue with the Fill type. As it is, users cannot extended it with different types without changing the framework source. I will create an issue about this.

@liuxuan30
Copy link
Member

liuxuan30 commented Dec 28, 2017

a long time ago, this PR is almost accepted, except for the code style problems, and then we are uncertain whether to go ahead without porting to android side, so many feature PRs are on hold since then. And Swift 3.0/4.0 kicks in, so more conflicts for this.

I think the implementation is accepted, so the next work is we reimplement this on your refactoring base and get it merged, as what I planned.

For the Fill part, this is something I predict you would have different opinions, before we simply solve the conflict and merge.

Another excuse from me is I spent all most my little free time looking at your PRs and other stuff, other are delayed.

@jjatie
Copy link
Collaborator

jjatie commented Dec 28, 2017

@liuxuan30 Would you like me to reimplement this in a clean branch so that we can get this merged? Seems like a great feature.

@liuxuan30
Copy link
Member

I would suggest you take some rest :) You already did a lot.

@jjatie
Copy link
Collaborator

jjatie commented Dec 28, 2017

Made current in #3142

@Ferszt
Copy link

Ferszt commented Jul 13, 2018

Hi, any updates on this? Do you have any idea when this feature will be available? Also, do you think the corresponding branch could be stable enough to use in an app? Thanks!

1 similar comment
@HebeTienCoder
Copy link

Hi, any updates on this? Do you have any idea when this feature will be available? Also, do you think the corresponding branch could be stable enough to use in an app? Thanks!

@Kalvin126
Copy link

guys... #3415 was merged and will be in version 4.0.0 which is not yet out.

@girishk55
Copy link

When we can expect to get the line gradient chart feature in Chart-iOS (version 4.0.0). As mentioned "guys... #3415 was merged and will be in version 4.0.0 which is not yet out."

@Jartz
Copy link

Jartz commented Mar 27, 2019

i use.
pod 'Charts', :git => 'https://github.com/danielgindi/Charts.git', :branch => '4.0.0'

`

func setDataCount(values: [ChartDataEntry]?) {
    
    let set1 = LineChartDataSet(values: values!, label: "DataSet 1")

    chartView.drawGridBackgroundEnabled = false

    set1.setColors(UIColor.init(red: 249/255, green: 192/255, blue: 45/255, alpha: 1), UIColor.init(red: 216/255, green: 36/255, blue: 38/255, alpha: 1))
    set1.isDrawLineWithGradientEnabled = true
    set1.gradientPositions = [0, 130]


    set1.lineWidth = 1.0
    set1.circleRadius = 3.0
    set1.fillAlpha = 1.0
    set1.drawFilledEnabled = true

    set1.drawCircleHoleEnabled = false
    set1.valueFont = .systemFont(ofSize: 9)
    set1.formLineDashLengths = [5, 2.5]
    set1.formLineWidth = 3
    set1.formSize = 15


    let iconRect = set1.iconsOffset
    set1.iconsOffset = CGPoint(x: iconRect.x + 8, y: iconRect.y)

    set1.drawFilledEnabled  = false
    set1.drawCirclesEnabled = false
    set1.drawIconsEnabled   = true
    set1.drawValuesEnabled  = false


    let data = LineChartData(dataSet: set1)
    chartView.data = data
}

`

Captura de pantalla 2019-03-27 a la(s) 1 39 36 p  m  (2)

@tri75
Copy link

tri75 commented Dec 31, 2019

The graph draw incorrect(I make the red circle in the attachment)

Data points for draw graph:

  1. (x: 1577639282.0, y: 10.0)
  2. (x: 1577640182.0, y: 9.0)
  3. (x: 1577641982.0, y: 7.0)
  4. (x: 1577642882.0, y: 7.0)
  5. (x: 1577644683.0, y: 7.0)
  6. (x: 1577645583.0, y: 7.0)
  7. (x: 1577647383.0, y: 7.0)
  8. (x: 1577648283.0, y: 7.0)
  9. (x: 1577650083.0, y: 6.0)
  10. (x: 1577650983.0, y: 7.0)
  11. (x: 1577652783.0, y: 11.0)
  12. (x: 1577653683.0, y: 16.0)
  13. (x: 1577655484.0, y: 22.0)
  14. (x: 1577656384.0, y: 26.0)
  15. (x: 1577658184.0, y: 34.0)
  16. (x: 1577659084.0, y: 36.0)
  17. (x: 1577660884.0, y: 49.0)
  18. (x: 1577661784.0, y: 49.0)
  19. (x: 1577663584.0, y: 48.0)
  20. (x: 1577664484.0, y: 46.0)
  21. (x: 1577666284.0, y: 45.0)
  22. (x: 1577667184.0, y: 44.0)
  23. (x: 1577668985.0, y: 48.0)
  24. (x: 1577669885.0, y: 43.0)
  25. (x: 1577671685.0, y: 49.0)
  26. (x: 1577672585.0, y: 48.0)
  27. (x: 1577674385.0, y: 68.0)
  28. (x: 1577675285.0, y: 64.0)
  29. (x: 1577677085.0, y: 62.0)
  30. (x: 1577677985.0, y: 58.0)
  31. (x: 1577679785.0, y: 65.0)
  32. (x: 1577680685.0, y: 65.0)
  33. (x: 1577693707.0, y: 35.0)
  34. (x: 1577694607.0, y: 30.0)
  35. (x: 1577696407.0, y: 32.0)
  36. (x: 1577697307.0, y: 31.0)
  37. (x: 1577698313.0, y: 58.0)
  38. (x: 1577698357.0, y: 42.0)
  39. (x: 1577698469.0, y: 33.0)
  40. (x: 1577699579.0, y: 33.0)
  41. (x: 1577700480.0, y: 35.0)

x: date time in second.

This attach is draw in: GMT +7

I'm using: pod 'Charts', :git => 'https://github.com/danielgindi/Charts.git', :branch => '4.0.0'

graph

Is it a bug of lib? please help me fix it. Thanks.

@StrauneanuDimitri
Copy link

@truongtantri - How did you get the chart to draw those gradient lines?

@tri75
Copy link

tri75 commented Jan 19, 2021

@StrauneanuDimitri
pod 'Charts', :git => 'https://github.com/danielgindi/Charts.git', :branch => '4.0.0'

and data points in my post.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.