Horizontal/Vertical
Line:
To insert Horizontal/Vertical
Lines, first create an IDataLineSet object that has a handle on the chart's
DataLines. Then, lines can be created through methods in the IHorzVertLine
and added to the chart through IDataLineSet.
// create a horizontal line . For vertical line, use IHorzVertLine.VERTICAL_LINE
IHorzVertLine hLine1 = hDataLines.newHorzVertLine(
// set data lines(not the inserted lines) to be red color above
the
// constant horizontal line 50; set data lines to be yellow below
50
// if chart type is not a "line" chart, you should set data connect
lines
// to be visible first--to see the effects.
hLine1.setColorAboveLine( Color.red);
hLine1.setColorBelowLine( Color.yellow);
// don't show in legend
hLine1.setTitleVisibleInLegend(false);
// set line color to blue
hLine1.setColor(Color.blue);
// set line thickness to 2 pixels
hLine1.setThickness(2);
// set line style to dash lines
// ((256 * Fill_pixel) + Empty_Pixel) * 256
// Note: fill_pixel and Empty_pixel must be less than 256
hLine1.setLineStyle(((256 * 8) + 5) * 256);
// add line to chart
hDataLines.add(hLine1);
// create an "AVERAGE" control line
IControlLine cLine1 = hDataLines.newControlLine(
// sets line title to "Average" in legend, instead of "label"
cLine1.setTitle("Average");
// set line color to red, thickness to 3 pixels
cLine1.setColor(Color.red);
cLine1.setThickness(3);
// set line style to dash lines
// ((256 * Fill_pixel) + Empty_Pixel) * 256
// Note: fill_pixel and Empty_pixel must be less than 256
cLine1.setLineStyle(((256 * 8) + 5) * 256);
// Add an annotation to the Control Line, "Average"
IAnnotationSet hAnnotation = chart.gethAnnotations();
IAnnotation anno1 = hAnnotation.newAnnotation("Average", cLine1);
// Add annotation to the line, add line to chart
cLine1.addAnnotation(anno1);
hDataLines.add(cLine1);
// line #1, Polynomial to the 5th degree
ITrendLine tr1 = hDataLines.newTrendLine(ITrendLine.POLYNOMIAL,
5,
"Degree 5 Poly fit");
// show title in legend
tr1.setTitleVisibleInLegend(true);
// set color to magenta
tr1.setColor(Color.magenta);
// set line thickness to 2 pixels
tr1.setThickness(2);
// set line style to dash lines
// ((256 * Fill_pixel) + Empty_Pixel) * 256
// Note: fill_pixel and Empty_pixel must be less than 256
tr1.setLineStyle(((256 * 8) + 5) * 256);
// line #2, moving average, 7 days
ITrendLine tr2 = hDataLines.newTrendLine(
// line #3, moving average, 14 days
ITrendLine tr3 = hDataLines.newTrendLine(
// add lines to the chart
hDataLines.add(tr1);
hDataLines.add(tr2);
hDataLines.add(tr3);
// creating a vector list of 4 points
java.util.Vector pointList = new java.util.Vector();
// use Point_2D objects to draw a line and attach it to the canvas.
// use Point_3D objects if you want to draw a line and attach it
to the chart
pointList.addElement(new Point_2D(0.2f, 0.8f));
pointList.addElement(new Point_2D(0.5f, 0.8f));
pointList.addElement(new Point_2D(0.5f, 0.6f));
pointList.addElement(new Point_2D(0.2f, 0.8f));
// construct a default PolyLine object, "polyLine"
PolyLine polyLine = new PolyLine();
// drawing the line and setting it to red
polyLine.set(pointList.elements(), Color.red);
// set starting point arrowhead invisible, false
polyLine.setArrowAtStartingPointVisible(false);
// set ending point arrowhead visible, true
polyLine.setArrowAtEndPointVisible(true);
// change color to blue
polyLine.setColor( Color.blue);
// set to fill the enclosed area
polyLine.setFillArea( true);
// set line style to dash lines, ((256*fillPixel)+emptyPixel)*256
// note: fillPixel, and emptyPixel must be less than 256
polyLine.setLineStyle( ((256*8) + 5)*256 );
// set thickness to 3 pixels
polyLine.setThickness(3);
// Get a handle to IFloatingLineSet
IFloatingLineSet hFloatingLines = chart.gethFloatingLines();
// add line to the chart
hFloatingLines.add(polyLine);