For downloads, demos, and more visit the
Client-side GChart Home Page

com.googlecode.gchart.client
Class GChart.Curve

java.lang.Object
  extended by com.googlecode.gchart.client.GChart.Curve
Enclosing class:
GChart

public class GChart.Curve
extends java.lang.Object

Represents a curve on a chart, which includes information such as the x,y coordinates of each point, the symbol used to represent points on the curve, etc.

To create a new curve, use the GChart.addCurve method.

See Also:
addCurve()

Nested Class Summary
 class GChart.Curve.Point
          Represents a single point on one of the chart's curves.
 
Method Summary
 void addPoint(double x, double y)
          Adds a new point to the curve, at the end of the current list of points, with the specified coordinates in model-units (arbitrary, application-specific, units).
 void addPoint(int iPoint, double x, double y)
          Adds a new point at the specified position in the point sequence, increasing the indexes of existing points at or after the specified position by 1.
 void clearPoints()
          Removes every point this curve contains.
 java.lang.String getHovertextTemplate()
          Deprecated. This method is equivalent to:

getSymbol().getHovertextTemplate()

It is retained only for GChart 1.1 compatibility purposes.

 java.lang.String getLegendLabel()
          Returns the HTML defining this curve's legend label.
 int getNPoints()
          Returns the number of points this curve contains.
 GChart.Curve.Point getPoint()
          Convenience method equivalent to getPoint(getNPoints()-1).
 GChart.Curve.Point getPoint(int iPoint)
          Returns a reference to the point at the specified index.
 GChart.Symbol getSymbol()
          Returns the symbol associated with this curve.
 com.googlecode.gchart.client.GChart.YAxisId getYAxis()
          Returns the y-axis (Y_AXIS or Y2_AXIS) this curve is plotted on.
 boolean isVisible()
          Is this curve visible on the chart and legend key, or is it hidden from view.
 boolean onY2()
          Convenience method equivalent to getYAxis()==Y2_AXIS.
 void removePoint(int iPoint)
          Removes the point at the specified index.
 void setHovertextTemplate(java.lang.String hovertextTemplate)
          Deprecated. This method is equivalent to:

getSymbol().setHovertextTemplate(hovertextTemplate)

It is retained only for GChart 1.1 compatibility purposes.

 void setLegendLabel(java.lang.String legendHTML)
          Sets the HTML that defines the label shown to the right of the icon representing the curve's symbol in the chart's legend.
 void setVisible(boolean isVisible)
          Defines if this curve is visible both in the plotting region and on the legend key.
 void setYAxis(com.googlecode.gchart.client.GChart.YAxisId axisId)
          Sets the y-axis that this curve is plotted on.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

addPoint

public void addPoint(double x,
                     double y)
Adds a new point to the curve, at the end of the current list of points, with the specified coordinates in model-units (arbitrary, application-specific, units).

If Double.NaN is specified for either x or y, the point is created, but it will not be visible in the charting region.

Tip: Dotted connecting lines to/from such a NaN points are elided, so you can use such a point to create a break in an otherwise connected curve.

Parameters:
x - the x-coordinate of the new point
y - the y-coordinate of the new point
See Also:
getPoint, addPoint(int,double,double), removePoint, clearPoints, getNPoints

addPoint

public void addPoint(int iPoint,
                     double x,
                     double y)
Adds a new point at the specified position in the point sequence, increasing the indexes of existing points at or after the specified position by 1.

Parameters:
iPoint - the position that the new point will occupy
x - the x-coordinate of the new point (model units)
y - the y-coordinate of the new point (model units)
See Also:
getPoint, addPoint(double,double), removePoint, clearPoints, getNPoints

clearPoints

public void clearPoints()
Removes every point this curve contains.

See Also:
Point, getPoint, addPoint(double,double), addPoint(int,double,double), removePoint, getNPoints

getHovertextTemplate

public java.lang.String getHovertextTemplate()
Deprecated. This method is equivalent to:

getSymbol().getHovertextTemplate()

It is retained only for GChart 1.1 compatibility purposes.

See Also:
Symbol.getHovertextTemplate

getLegendLabel

public java.lang.String getLegendLabel()
Returns the HTML defining this curve's legend label.

Returns:
the legend label HTML for this curve
See Also:
setLegendLabel

getNPoints

public int getNPoints()
Returns the number of points this curve contains.

Returns:
the number of points this curve contains.
See Also:
getPoint, addPoint(double,double), addPoint(int,double,double), removePoint, clearPoints

getPoint

public GChart.Curve.Point getPoint()
Convenience method equivalent to getPoint(getNPoints()-1).

This method makes code more readable for the common case when you first add a point to the end of a curve, and then modify that point's attributes, as illustrated below:

   class MyChart extends GChart {
     public MyChart() {
       addCurve();
       for (int i=0; i < 10; i++) {
         getCurve().addPoint(i,i);
         getCurve().getPoint().setAnnotationText("Point " + i);
       }
       update();
     }
   }
 

Returns:
the point on the curve with the highest integer index
See Also:
getPoint(int), getNPoints()

getPoint

public GChart.Curve.Point getPoint(int iPoint)
Returns a reference to the point at the specified index. The returned reference can be used to modify various properties of the point, such as its optional annotation (text label).

Parameters:
iPoint - the index of the point to be returned.
Returns:
a reference to the Point at the specified index.
See Also:
addPoint(double,double), addPoint(int,double,double), removePoint, clearPoints, getNPoints

getSymbol

public GChart.Symbol getSymbol()
Returns the symbol associated with this curve.

Though you cannot set the symbol itself (there is no setSymbol method) you can have essentially the same effect by setting the SymbolType (to get qualitatively different kinds of symbols, e.g. bar-chart bars vs boxes) and by changing symbol attributes such as background color, height, and width.

Returns:
the symbol used to represent points on this curve
See Also:
Symbol.setSymbolType, Symbol.setBackgroundColor, Symbol.setBorderWidth, Symbol.setBorderStyle, Symbol.setWidth, Symbol.setHeight, Symbol.setModelWidth, Symbol.setModelHeight

getYAxis

public com.googlecode.gchart.client.GChart.YAxisId getYAxis()
Returns the y-axis (Y_AXIS or Y2_AXIS) this curve is plotted on.

Returns:
an identifier, either Y_AXIS, or Y2_AXIS, indicating if this curve is plotted on the left (y) or right (y2) y-axis
See Also:
setYAxis, Y_AXIS, Y2_AXIS

isVisible

public boolean isVisible()
Is this curve visible on the chart and legend key, or is it hidden from view.

Returns:
true if the curve is visible, false otherwise.
See Also:
setVisible

onY2

public boolean onY2()
Convenience method equivalent to getYAxis()==Y2_AXIS.

Returns:
true if curve is on second y-axis, else false
See Also:
getYAxis

removePoint

public void removePoint(int iPoint)
Removes the point at the specified index.

Parameters:
iPoint - index of point to be removed.
See Also:
getPoint, addPoint(double,double), addPoint(int,double,double), clearPoints, getNPoints

setHovertextTemplate

public void setHovertextTemplate(java.lang.String hovertextTemplate)
Deprecated. This method is equivalent to:

getSymbol().setHovertextTemplate(hovertextTemplate)

It is retained only for GChart 1.1 compatibility purposes.

See Also:
Symbol.setHovertextTemplate

setLegendLabel

public void setLegendLabel(java.lang.String legendHTML)
Sets the HTML that defines the label shown to the right of the icon representing the curve's symbol in the chart's legend.

Setting the legend label to null removes the entire row (the label and the icon) associated with this curve from the chart key.

Note that, since null is the default, unless you set at least one legend label, no chart key will appear at all.

Parameters:
legendHTML - the HTML defining this curve's legend label. or null to remove the curve from the legend entirely.
See Also:
getLegendLabel

setVisible

public void setVisible(boolean isVisible)
Defines if this curve is visible both in the plotting region and on the legend key.

Notes:

  1. A curve must also have a non-null legend label if it is to appear on the legend key.

  2. Hidden curves are excluded from the computation of any auto-computed axis limits.

Parameters:
isVisible - false to hide curve, true to reveal it.
See Also:
isVisible, setLegendLabel

setYAxis

public void setYAxis(com.googlecode.gchart.client.GChart.YAxisId axisId)
Sets the y-axis that this curve is plotted on.

Parameters:
axisId - must be either GChart.Y_AXIS or GChart.Y2_AXIS
See Also:
getYAxis, Y_AXIS, Y2_AXIS

For downloads, demos, and more visit the
Client-side GChart Home Page

Copyright © 2007,2008 John C. Gunther. All Rights Reserved.