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

Customised size of x data points and Scatter Graph with Linear Trend Line #1274

Closed
NyoSeintLay opened this issue Jul 29, 2016 · 5 comments
Closed

Comments

@NyoSeintLay
Copy link

Hi Daniel,

Thanks for your awesome library and I have full of hopes that your library can be useful in my first swift application.
I just started a few graphs and stucking on one part.
I would like to create in final is scatter graph with Linear trendline as shown in figure A.
Now I am getting with this lib is as shown in Figure B.

Question 1
Could we change customised size of X-data points ?
now X-axis data point are always same size.
For eg -
Xaxis - 4.7, 9.41, 18.81, 37.6, 75.6
Yaxis - 0.035, 0.146, 0.373, 0.912, 2.276
Question 2
How can I draw Linear trend line (if possible - R square value included)?

I was wondering if you or other contributors can reply my questions.

Thanks and Regards,
NyoSeint Lay

figure a
figure b

@liuxuan30
Copy link
Member

liuxuan30 commented Jul 29, 2016

Q1: X axis is index based axis currently, so you can't; however, the good news is both Android and iOS library is working on v3.0 to support this. It should be coming soon, but no ETA yet; remember to watch this repo:)

You can of course tweak this library to draw figure a, but I don't think it's a smart choice for you, so just wait.

Q2: drawing trend lines requires knowledge of CoreGraphics; if you are not familiar with it, grab some tutorials; basically, you should know the (x,y) pairs to connect as trend lines if it's not linear.

for linear trend line, consider y = kx+b, so you only need two pairs to draw the line
for figure b, if you are familiar with cubic line drawing, then you can just connect those 5 points; if not, then you probably need like 100 data points to connect as line segment as a curve;(more points means smoother, right?)

You can take your figure b data to draw it as cubic line first to see if it meets your goals; to draw as cubic, set LineChartDataSet.mode = HorizontalBezier or CubicBezier

To get started, take a look at how ChartLimitLine is implemented; for cubic line, check drawHorizontalCubic() implementations

@liuxuan30
Copy link
Member

liuxuan30 commented Jul 29, 2016

I just saw v3.0 branch synced with master. You can be the first user.. :) use at your own risk

@NyoSeintLay
Copy link
Author

Ohh .. yes. How good luck I am.
Just now I was tested with V3 by using new " iChartDataSet"
ChartDataEntry parameter Changes
ChartDataEntry(value: values[i], xIndex: i) -> ChartDataEntry(x: xPoints[i],y: yPoints[i])

Now I am facing one issue is to add ChatDataEntry objects to iChartDataSet array.
I cannot create iChartDataSet object (may be don't know how to do)
Could u give me some advice for this ?
Thanks in advance, I will be grateful for any help you can provide.

The following is my setChart Function code:

var iChartDataSets: [IChartDataSet] = []
for i in 0..<xPoints.count {
// let dataEntry = ChartDataEntry(value: values[i], xIndex: i)

        let dataEntry = ChartDataEntry(x: xPoints[i],y: yPoints[i])

        let iChartDataset = ?? //Need to create IChartDataSet Object
        iChartDataSet.addEntry(dataEntry)

        iChartDataSets.append(iChartDataset)

    }

    let scatterChartData = ScatterChartData(dataSets: iChartDataSets)
    scatterChartView.data = scatterChartData
    scatterChartView.xAxis.labelPosition = .Bottom

@liuxuan30
Copy link
Member

liuxuan30 commented Jul 30, 2016

you should not use iChartDataSet, they are protocols. Use Concrete classes from standard implementation

@NyoSeintLay
Copy link
Author

Thats right.. my mistake.. I was on leave and cannot get back to this issue
Thanks for your advice.
Now I can set value (x,y) with customised x axis with V3 Library.
^.^

screen shot 2016-08-03 at 10 59 40 am

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

No branches or pull requests

2 participants