Results 1 to 6 of 6
 03222017, 01:36 PM #1Senior Member
 Join Date
 Mar 2013
 Location
 Greece
 Posts
 183
 Rep Power
 7
How to draw Polynomial Trendline in JavaFX
Greetings.
First of all, I would like to give some details about the background of this project. I was searching all over the internet for a ScatterChart or LineChart which can represent data on 2 YAxis ( each one of them has a different scale ). I couldn't find anything good in native JavaFX ( without any use of external API ) so I decided to create on for myself. (Yes sometimes I tend to reinvent the wheel :P )
The creation of the chart is made with the code below :
Java FX Code:CustomAxis xAxis = new CustomAxis(0, 160, 20); CustomAxis y1Axis = new CustomAxis(0, 100, 10); CustomAxis y2Axis = new CustomAxis(2150, 2500, 50); TwoAxisScatterChart chart = new TwoAxisScatterChart(850, 500, xAxis, y1Axis, y2Axis); chart.addValue(0, 10 , TwoAxisScatterChart.FIRST_Y_AXIS); chart.addValue(10, 22, TwoAxisScatterChart.FIRST_Y_AXIS); chart.addValue(5, 34, TwoAxisScatterChart.FIRST_Y_AXIS); chart.addValue(28, 78, TwoAxisScatterChart.FIRST_Y_AXIS); chart.addValue(39, 37, TwoAxisScatterChart.FIRST_Y_AXIS); chart.addValue(70, 11, TwoAxisScatterChart.FIRST_Y_AXIS); chart.addValue(48, 64, TwoAxisScatterChart.FIRST_Y_AXIS); chart.addValue(100, 2298 , TwoAxisScatterChart.SECOND_Y_AXIS); chart.addValue(110, 2193, TwoAxisScatterChart.SECOND_Y_AXIS); chart.addValue(120, 2469, TwoAxisScatterChart.SECOND_Y_AXIS); chart.addValue(130, 2332, TwoAxisScatterChart.SECOND_Y_AXIS); chart.addValue(140, 2404, TwoAxisScatterChart.SECOND_Y_AXIS); chart.addValue(150, 2399, TwoAxisScatterChart.SECOND_Y_AXIS); chart.addValue(160, 2240, TwoAxisScatterChart.SECOND_Y_AXIS);
My chart looks something like the image above and it's all created using shapes ( Lines, Text, Circles ) which are drawn into a 'Region' ( I am not very fond of Canvas to say the truth ). The position of each element ( Axis, Values, Title ) is calculated at runtime depending on the Stage dimensions. I was thinking to upload this entire project into GitHub and share it, but before I do that I want to make it as much portable as I could.
Everything works very smoothly and now I would like to more utilities. I want to give the user the ability to draw a 'trend line' ( Polynomial, Linear ). Right now I stack on computations of those lines but I believe I will manage. The question I have is about drawing such a shape in JavaFX. Well in a case of linear trendline the question is trivial but what about polynomial? What shape do I need to use in order to achieve that?
Polynomial TrendLine should like something like that :
Sorry for the long post. Thank for your time.Last edited by ShadowWalker; 03222017 at 01:46 PM.
 03222017, 02:23 PM #2Senior Member
 Join Date
 Sep 2014
 Location
 MA, USA
 Posts
 398
 Rep Power
 6
Re: How to draw Polynomial Trendline in JavaFX
Do you want the user to draw these lines in there or do you want the machine to create lines from linear/polynomial regression?
 03222017, 02:41 PM #3Senior Member
 Join Date
 Mar 2013
 Location
 Greece
 Posts
 183
 Rep Power
 7
Re: How to draw Polynomial Trendline in JavaFX
I would like to have a method like
Java FX Code:.showPolynomialTrendLine(TwoAxisScatterChart.FIRST_Y_AXIS)
I checked this website
Thorwin: Trend Curve/Line in JavaFX Chart
where he uses an external math API to find the coefficients points and after that he draw multiple points like the code below to make a curved line.
Java FX Code:for (double x = 0; x <= 5.0; x += 0.05) { double y = polynomial(x, coefficients); series2.getData().add(new XYChart.Data<>(x,y)); }
If for example there was a JavaFX shape where I could say " Draw a line/curve which goes through all points[] " this will be trivial, but I believe that there is not something like that.Last edited by ShadowWalker; 03222017 at 02:46 PM.
 03222017, 03:47 PM #4Senior Member
 Join Date
 Sep 2014
 Location
 MA, USA
 Posts
 398
 Rep Power
 6
Re: How to draw Polynomial Trendline in JavaFX
I guess this is post is more about the linear/ polynomial regression algorithms rather than the display in JavaFX.
I would look for publications that deal with big data regressions. I am sure there is some literature out there. I would google something like "big data regression techniques"
 03222017, 03:54 PM #5Senior Member
 Join Date
 Mar 2013
 Location
 Greece
 Posts
 183
 Rep Power
 7
Re: How to draw Polynomial Trendline in JavaFX
I was searching it with "Linear Trendline" term so didn't find at lot about it. I see with "linear/ polynomial regression" ( which I now believe is the correct term) there are a lot of publications. Thank you very much for the information you gave me!! I hope I will find an efficient way to represend it in JavaFX.
 04022017, 01:50 AM #6Senior Member
 Join Date
 Mar 2013
 Location
 Greece
 Posts
 183
 Rep Power
 7
Re: How to draw Polynomial Trendline in JavaFX
I complete the entire project and if anyone ( now or in the future ) want to give it a look or just use it, you may find it on GitHub
https://github.com/JKostikiadis/MulitAxisScatterChart
( I hope I am not violating any forum rule by posting another site's link. )
I will try to keep it updated as much as I can ( and of course if needed ).
Similar Threads

JavaFX Book  Learn JavaFX More In Depth
By SnakeDoc in forum JavaFXReplies: 0Last Post: 05182013, 12:10 AM 
work to do about Polynomial
By Joana in forum New To JavaReplies: 14Last Post: 04152012, 08:54 AM 
Polynomial Graphing help
By captain in forum New To JavaReplies: 1Last Post: 12012011, 01:53 PM 
JavaFX Script and JavaFX Mobile
By levent in forum Java SoftwareReplies: 1Last Post: 01272010, 05:48 PM 
Help with polynomial program
By susan in forum New To JavaReplies: 1Last Post: 08072007, 05:44 AM
Bookmarks