A regression line is a statistical tool used to predict future values from past values. The
values of a linear regression line are calculated using a best-fit method (least squares) to
place a straight line in the exact middle of a series data points. Linear regression lines are
largely used in trend analysis.
A regression line is an instance of the class com.jinsight.jetchart.RegressionLine, held
by subclasses of com.jinsight.jetchart.GraphSerie and com.jinsight.jetchart.ScatterSerie.
It can be plotted against almost all series supported by the chart contexts represented by the
classes Graph and ScatterGraph. The only exception are stacked bar series.
The following example displays a linear regression line plotted against a line series.
import java.awt.*; import java.awt.event.*; import javax.swing.*; import com.jinsight.jetchart.*; public class Main extends JFrame { public Main() { Graph graph=new Graph(); graph.setTitle(new String[]{"The JetChart Library","Regression lines"}); ScrollingLabel sl=graph.getScrollingLabel(); sl.setEnabled(true); GraphSet graphSet=graph.getGraphSet(0); ScrollingBar sb=graphSet.getScrollingBar(); sb.setEnabled(true); ToolTip tt=graph.getToolTip(); tt.setEnabled(true); tt.setMultipleEnabled(true); String[] labels={"1950","1951","1952","1953","1954", "1955","1956","1957","1958","1959", "1960","1961","1962","1963","1964", "1965","1966","1967","1968","1969", "1970","1971","1972","1973","1974", "1975","1976","1977","1978","1979", "1980","1981","1982","1983","1984", "1985","1986","1987","1988","1989", "1990","1991","1992","1993","1994", "1995"}; graph.setLabels(labels); double[] values={631,645,704,717,709,759,794,794,784, 849,847,822,864,865,921,917,1005,1029, 1069,1078,1096,1194,1156,1272,1220,1250, 1363,1337,1467,1428,1447,1499,1550,1486, 1649,1664,1683,1612,1564,1685,1780,1696, 1776,1703,1745,1685}; LineSerie ls=new LineSerie(values,"Line series"); ls.setColor(Color.red); ls.setMarksEnabled(false); ls.setThickness(2); graph.addSerie(ls); RegressionLine rl=ls.getRegressionLine(); rl.setEnabled(true); rl.setColor(Color.blue); rl.setThickness(2); Scale scale=graphSet.getScale(); scale.setAutoScaleEnabled(false); scale.setMaxValue(2000); scale.setMinValue(400); scale.setIncrement(400); scale.setValueFormat("#,###"); scale.setPosition(Scale.LEFT_RIGHT); Container ct=getContentPane(); ct.add(graph); setSize(500,400); setVisible(true); } public static void main(String[] args) { new Main(); } }