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()

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()
          Returns the hovertextTemplate of the given curve.
 java.lang.String getLegendLabel()
          Returns the HTML defining this curve's legend label.
 int getNPoints()
          Returns the number of points this curve contains.
 GChart.Point getPoint()
          Convenience method equivalent to getPoint(getNPoints()-1).
 GChart.Point getPoint(int iPoint)
          Retrieves 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()
          Retrieves 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)
          Defines the "hovertext" that appears whenever the user points their mouse at a point on the curve.
 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 in the plotting region and on the legend key, or not.
 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.

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()
Returns the hovertextTemplate of the given curve.

Returns:
hovertextTemplate of the curve
See Also:
setHovertextTemplate

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.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.Point getPoint(int iPoint)
Retrieves 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()
Retrieves 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)
Defines the "hovertext" that appears whenever the user points their mouse at a point on the curve.

Two special keywords, XXX and YYY, are supported within the hovertext String. The first occurrence of "XXX" in the string will be replaced with the x-coordinate of the point, formatted as per the specified tick label format of the x-axis. The first occurrence of "YYY" within the string will be replaced with the y-coordinate of the point, formatted either using the y-axis or y2-axis tick label format, depending on the axis on which the curve is displayed.

HTML is not supported within hovertext.

Parameters:
hovertextTemplate - defines the hoverText to display when the mouse moves over a point on this curve, with XXX and YYY indicating where the x and y coordinates of the point will appear within this text.
See Also:
getHovertextTemplate, DEFAULT_HOVERTEXT_TEMPLATE

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.

Parameters:
legendHTML - the HTML defining this curve's legend label.
See Also:
getLegendLabel

setVisible

public void setVisible(boolean isVisible)
Defines if this curve is visible in the plotting region and on the legend key, or not. Hidden curves are also excluded from the computation of any auto-computed axis limits.

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

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