Code Monkey home page Code Monkey logo

Comments (4)

owlmafia avatar owlmafia commented on May 11, 2024

That should not be a problem because the axis values and the chart points are independent from each other.

Only the axis values have to be sorted. You can for example define the x-values like this to display regular intervals:

Array(stride(from: myXMin, through: myXMax, by: 5)).map {ChartAxisValueInt($0, labelSettings: labelSettings)}

Then you can pass your original, unsorted chartpoints to the chart points layer which is in charge of displaying the lines.

I suggest you look in the examples, there are many which show a line, and adjust them to do what you want. You probably will have to replace

chartPoints.map{$0.x}

with your function to determine the x values, as described above. map works in these examples because the x-values of the chart points are sorted.

That aside, there's no really a scatter plot in this library, but a scatter layer - to display lines between the points you just have to add a line layer on top (or behind) of it.

Edit:
I'm now not sure if I'm misinterpreting the question, if with x = [0, 20, 30, 35, 25, 0] you mean that the axis should show these values this is not possible, as the chart would have 2 possible locations to draw a point and would not know which one.

Besides of that, it's possible to have multiple y values for an x value.

from swiftcharts.

car92 avatar car92 commented on May 11, 2024

No, that works perfectly thank you for that.

I was wondering if you could help me with one more thing - I have attached an image of the situation. I've changed to the touch interactive graph as I see as you explained that works perfectly for my situation.

Now, since I have two y-values for the single x-value, I want the touch capability to be able to work for both values, whichever the user clicks closest to, however at current it seems that it only works for the upper values of y (in that image I had clicked at a y-value of 2). Is the touch setting adjusted such that it selects the value on the basis of x-value alone? Is there a way to change it so it goes to the nearest point alone?
screen shot 2015-07-08 at 9 23 07 am
Thanks again.

from swiftcharts.

owlmafia avatar owlmafia commented on May 11, 2024

Ah, well, that is not supported. Currently it selects the first intersection, which depends on the order in which you added the chart points. But I think you can implement it easily, if you go to https://github.com/i-schuetz/SwiftCharts/blob/master/SwiftCharts/Layers/ChartPointsLineTrackerLayer.swift#L159 and modify it to collect all the intersections, then choose the one with the smallest distance to the touch point. If the code is generic enough you also can submit a PR after it :)

from swiftcharts.

owlmafia avatar owlmafia commented on May 11, 2024

I implemented the handling for multiple intersections. It's now in master.
f21bb63

Thanks for the idea!

from swiftcharts.

Related Issues (20)

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.