Constant Lines & Stripes

Constant lines

Constant lines are some of the most useful objects when it comes to highlighting information in the chart area. You may want to create constant lines to highlightlimits or specific points of interest in the chart. For example, in a scientific application, you may want to use the constant line object to highlight an alarm limit, or in a financial application you may want to highlight a target price or date.

Constant lines are lines that you can draw anywhere in the chart area and associate them with a particular value in the axis that they're assigned to, as illustrated in the following figure.

All constant lines are handled by the Line and ConstantLine classes and their supported members. Using the Line class, you can control the line color, styles and width. The ContstantLine class members allow control over other attributes such as the associated axis.

Creating a constant line does not require a new data series and you can also configure labels and line styles, colors and width. If you wish to highlight a range of values instead of a specific value, please refer to the Stripe sample next in this section.

The following code creates the constant lines for the previous figure shown.


ConstantLine constantHorz = chart1.getConstantLine(0);
constantHorz.setValue(30);
constantHorz.setColor(java.awt.Color.red);
constantHorz.setAxis(AxisItem.Y);
constantHorz.setText("Alarm Limit 1");
constantHorz.setWidth(1);

ConstantLine constantVert = chart1.getConstantLine(1);
constantVert.setValue(3);
constantVert.setColor(java.awt.Color.orange);
constantVert.setAxis(AxisItem.X);
constantVert.setText("Limit 2");
constantVert.setWidth(3);

Stripes

Stripes can also be very useful objects to highlight information in the chart area. They allow you to highlight a range of values associated with any of the axes by drawing a color frame in the chart background. For example, in a scientific application you may want the user to recognize points that plot between 20 and 80 with a blue stripe object as depicted in the following figure

The Stripe object handles stripes and their properties, where you can set color, range and which axis the stripe is associated to. If you want to highlight a specific value instead of a range, please refer to the Constant Lines sample in the previous section.

The following code creates the stripes for the previous figure shown.


Stripe stripeHorz = chart1.getStripe(0);
stripeHorz.setFrom(20);
stripeHorz.setTo(50);
stripeHorz.setColor(new java.awt.Color(192,192,255,85));
stripeHorz.setAxis(AxisItem.Y);

Stripe stripeVert = chart1.getStripe(1);
stripeVert.setFrom(3);
stripeVert.setTo(5);
stripeVert.setColor(new java.awt.Color(128,255,128,85));
stripeVert.setAxis(AxisItem.X);