Most of the code is already familiar to Java developers:
Lines 1-15 provide the necessary imports.
Line 17 says that our class inherits a JFrame in order to display a chart.
Line 20 defines the start of the constructor.
Line 24 defines the array that holds x-axis values of our chart.
Lines 27-28 define the array that holds y-axis values of our chart.
Line 30 defines ChartDataModel that will be used for BarSeries creation.
Line 33 creates an axis mapper for Y axis. We pass the axis range to mapper constructor – the defined range will be 80 units of measurement, that means that y-axis will display values from 0 to 80.
Line 36 creates an axis mapper for X axis. We pass an array of labels to constructor.
Lines 39-45 show how the BarSeries object is created. We pass a DataModel to it (created from two arrays that form a corresponding value pairs - Animal and Speed). Both axes are also passed to series constructor.
Line 40 creates BarSeries object with provided parameters.
Line 42 sets bars color.
Line 43 sets bars foreground color.
Line 45 sets title of BarSeries, which will be displayed in legend.
Lines 47-55 declare that the x-axis is created using mapper defined above. Axis is customized directly and via stylesheet.
Line 48 creates axis for X coordinates which will use mapper declared above.
Line 50 sets a title for the x-axis.
Line 52 sets the position of the x-axis title.
Line 54 sets the label font of x-axis.
Line 55 sets the title font of x-axis.
Lines 57-65 declare that the y-axis is created using mapper defined above. Axis is customized directly and via stylesheet.
Line 58 declares that y-axis will use the mapping declared above.
Line 60 sets the title for y-axis.
Line 62 sets the position of the y-axis title.
Line 64 sets label font of y-axis.
Line 65 sets the font of the title of the y-axis.
Line 69 creates a Grid object. Grid grid=new Grid (new PlaneMapper2D(), null, yMapper); First parameter is used to determine the chart display area, we have no limitations so we pass an empty PlaneMapper2D object. Second parameter is a mapper for X axis (we pass null because we do not want vertical lines). Third parameter is a mapper for Y axis (horizontal lines).
Lines 71-77 create Chart2D object that acts as a container for all other visual elements. All visible chart objects are passed to setObjects function. X and Y axes are set in that way that the Chart2D could know the data visible range, scaling and etc.
Line 72 creates Char2D object.
Line 74 sets objects that will be displayed in chart.
Line 76 sets x-axis for chart which will appear at the bottom.
Line 77 sets y-axis for chart.
Lines 79-83 create a Legend for this chart.
Line 78 creates legend for chart.
Line 82 sets for for legend.
Line 83 sets legends background.
Lines 85-90 create a LabeledChart – a View implementation displays the title above the chart, footer below it. Also, we add Legend to LabeledChart, what is done in line 90: topChart.setBottomView (Legend).
Line 91 adds the chart to a ContentPane object.
Lines 96-101 invoke the QuickStartDemonstration constructor and display the chart on the screen.