Comments (4)
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.
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?
Thanks again.
from swiftcharts.
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.
I implemented the handling for multiple intersections. It's now in master.
f21bb63
Thanks for the idea!
from swiftcharts.
Related Issues (20)
- Static library
- Temporarily hide lines in Line chart
- What's the correct way to set contentView background color and border? HOT 1
- Is this kind of y axis layout possible:
- Extending Views to create custom views isn't working due to file private and internal properties
- How to overlay a layer of labels?
- Axis disappear after coming back from background
- X Y points in horizontal bar chart keeps moving rights; when the y axis labels length (text) is more
- Swift 5
- Changing axis values
- X values not adding properly
- Axis Labels not showing up HOT 2
- ChartLabelSettings() ignoring supplied font color, always defaults to black HOT 1
- SPM Support?
- Problem building on new MacBook
- SPM not working properly due to missing TAG HOT 1
- x, y Axis didn't show in the Chart HOT 2
- ChartPointsBubbleLayer not draws properly HOT 1
- how to dynamic live update line chart
- How can i make xAxisLabel to get multiple data instead of one value for one xAxisLabel ?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from swiftcharts.