how to implement chart and graph in java?
I want to create a chat and graph on the basis of give input in Java.i don't have an idea about to how to implement chart and graph in Java. pl开发者_Go百科ease give me some idea about the implementation.
Thanks
Go for JFreeChart.
Here is nice tutorial with Example
Here is very good article from java world
If you want to implement graph yourself, first get your x, y points in two arrays xarray[]
, yarray[]
. Normally to implement a curved graph, you need points between the data points you already have. Use interpolation for this www.webcabcomponents.com has free version of interpolation program. You just give the xarray
, yarray
, any_x
and you get the interpolated y point for any x. You can plot look-continuous curves by code like
[pseudo code]
firstX,firstY =0 //assumed x=0; y(0)=0
loop
for x= 0 to panel width;
{ get interpolatedY(x);
drawLine from (firstX,firstY) to (nextX,nextY);
//use Graphics.drawLine command
firstX=nextX; firstY=nextY;
}
You may have to set Scale if necessary and multiply the firstX
etc by scale.
For Interpolation these bit of code will get you started. returnedArray
has two elements. First returnedArray[0]
is the required y. The other is error estimate (neglect for now).
import webcab.lib.math.interpolation.Interpolation;
Interpolation interpol1 = new Interpolation();
double[] returnedArray = interpol1.interpolateExtrapolatePolynomial(getQArray(),getEArray(),x);
y=returnedArray[0];
The above method interpolateExtrapolatePolynomial(getQArray(),getEArray(),x)
is for polymial type curves. If you data points do follow any other pattern class, Interpolation has other methods. Or you can implement yourself using numerical methods.
Happy coding!
Use http://www.jfree.org/jfreechart/ It's technically Open Source.
精彩评论