These markers draw a line on particular axis area. There are two types of MarkerLine - Horizontal and Vertical. HorizontalMarkerLine is displayed in parallels with x-axis, whilst VerticalMarkerLine is displayed in parallels with y-axis. Thus, levels of these MarkerLine should be set in such way, that mappers would be able to map them. For instance, there is y-axis with MathAxisMapper and x-axis with DateAxisMapper. When setting level for VerticalMarkerLine level should be set from range of MathAxisMapper, and HorizontalMarkerLine - from range of DateAxisMapper.
Setting markers:
1 | // calculates mean value of data model double val1 = Statistics.mean(data1, DataColumnType.VALUE); // creates a new HorizontalMarkerLine object named m HorizontalMarkerLine m = new HorizontalMarkerLine(new PlaneMapper2D(),yMapper); // sets place where marker should stand m.setLevel(val1); // sets label m.setLabel("Mean: AMD Athlon 64"); // sets marker's text font m.getTextStyle().setFont((new Font ("Arial", Font.BOLD, 9))); // sets marker's line color m.getPaintStyle().setForeground(new Color(251, 178, 47).darker()); |
Figure 5.6.5.1 MarkerLine Demonstration
There are several methods that enable setting and changing properties of markerRange such as title, position and so on. Below is the code, illustrating markerLine settings. However, markerLine background, foreground colors and other options related to style such as stroke, can be set using getPaintStyle() and getTextStyle() methods.
It is possible to set title for markerLine, which will appear on chart. This can be done using setLabel() method.
//sets marker title m.setLabel("Mean: AMD Athlon 64"); |
MarkerLine label style can be set by using html tags.
//sets marker title style with html tags m.setLabel("<html><body style=\"background-color:green\"/>" + "<font color=red size=+1>Mean: AMD Athlon 64</font>"); |
Also it is possible to set markerLine label's position using setLabelPosition() method.
mM.setLabelPosition(0.65, Alignment.TOP); |
In order to set position where marker range line should appear, setLevel() method must be used. Parameter's value represents mapper's value where line should appear. However, when setting this value, mapper which was set for marker range must be able to map this value. That is, if we set markerLine with MathAxisMapper, then using this method parameter must be value which MathAxisMapper is able to map and from its range.
Setting MarkerLine object's position
double valM = Statistics.mean(dataM, DataColumnType.VALUE); mM.setLevel(valM); |