|
For downloads, demos, and more
visit the Client-side GChart Home Page |
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectcom.google.gwt.user.client.ui.UIObject
com.google.gwt.user.client.ui.Widget
com.google.gwt.user.client.ui.Composite
com.googlecode.gchart.client.GChart
public class GChart
A GChart can represent and display a line chart, a bar chart, a pie chart, an area chart, or a chart that contains arbitrary combinations of line, bar, pie, and/or area based curves.
For detailed examples, with screen shots, visit the Chart Gallery.
For detailed instructions on how to integrate Client-side GChart into your GWT application, see Installing Client-side GChart.
CSS Style Rule
USE_CSS for a detailed description of these CSS convenience methods--which
won't interfere with standard CSS-based specifications if you never invoke
them.
| Nested Class Summary | |
|---|---|
static class |
GChart.AnnotationLocation
Defines the location of a data point's annotation or hover annotation (which can be defined by either plain text, HTML, or a widget) relative to the location of that point's symbol. |
class |
GChart.Axis
Represents an axis of the chart, for example, the x, y, or y2 axis. |
class |
GChart.Curve
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. |
static class |
GChart.LegendLocation
Defines keywords that specify the location of the legend on the chart. |
class |
GChart.Symbol
Defines a chart curve symbol. |
static class |
GChart.SymbolType
Specifies the type of symbol used by a curve. |
static class |
GChart.TickLocation
Defines keywords INSIDE, OUTSIDE, and CENTERED that specify the location of ticks relative to their axis. |
static class |
GChart.TouchedPointUpdateOption
Defines how the update method updates the touched point, that is, the point the user is considered to be hovered over. |
class |
GChart.XAxis
The x-axis of a GChart. |
class |
GChart.Y2Axis
The right, or "y2", axis of a GChart. |
class |
GChart.YAxis
The left y-axis of a GChart. |
| Nested classes/interfaces inherited from class com.google.gwt.user.client.ui.UIObject |
|---|
com.google.gwt.user.client.ui.UIObject.DebugIdImpl, com.google.gwt.user.client.ui.UIObject.DebugIdImplEnabled |
| Field Summary | |
|---|---|
static int |
DEFAULT_ANNOTATION_FONTSIZE
Default size, in pixels, of text used to annotate individual plotted points on a curve. |
static double |
DEFAULT_BAR_FILL_SPACING
The default spacing between discrete, rectangular, elements used to simulate continuous filling of polygonal regions formed by connecting corresponding ends of successive bars in a bar chart. |
static java.lang.String |
DEFAULT_BLANK_IMAGE_URL
The default URL GChart will use to access the blank image (specifically, a 1 x 1 pixel transparent GIF) it requires to prevent "missing image" icons from appearing in your charts. |
static java.lang.String |
DEFAULT_BLANK_IMAGE_URL_FULLPATH
The full path to the default GChart blank image (specifically, a 1 x 1 pixel transparent GIF) it requires to prevent "missing image" icons from appearing in your charts. |
static int |
DEFAULT_BRUSH_HEIGHT
Default pixel height of rectangular "brush" that defines how close the mouse cursor must be to a rendered symbol for it to be "touched" (which pops up its hover feedback). |
static int |
DEFAULT_BRUSH_WIDTH
Default pixel width of rectangular "brush" that defines how close the mouse cursor must be to a rendered symbol for it to be "touched" (which pops up its hover feedback). |
static java.lang.String |
DEFAULT_FONT_COLOR
The default color of any text appearing in a chart's legend, annotations, or tick labels. |
static java.lang.String |
DEFAULT_FONT_FAMILY
The font-family that GChart uses by default for all textual annotations on a chart (tick labels, point annotation, legend key text, titles, and footnotes). |
static java.lang.String |
DEFAULT_FONT_STYLE
Default style of axis label and legend fonts. |
static java.lang.String |
DEFAULT_FONT_WEIGHT
Default weight of axis label and legend fonts. |
static int |
DEFAULT_FOOTNOTES_THICKNESS
The default thickness (height) of the rectangular region at the bottom of the chart allocated for footnotes, per <br> or <li> delimited HTML line. |
static java.lang.String |
DEFAULT_GRID_COLOR
The default color used for all axes, gridlines, and ticks. |
static GChart.AnnotationLocation |
DEFAULT_HBAR_BASELINE_HOVER_LOCATION
The default location used to position the hover feedback when the user hovers their mouse above a point on a curve that uses a HBAR_BASELINE_* symbol type. |
static GChart.AnnotationLocation |
DEFAULT_HBARLEFT_HOVER_LOCATION
The default location used to position the hover feedback when the user hovers their mouse above a point on a curve that uses an HBAR_*WEST symbol type. |
static GChart.AnnotationLocation |
DEFAULT_HBARRIGHT_HOVER_LOCATION
The default location used to position the hover feedback when the user hovers their mouse above a point on a curve that uses an HBAR_*EAST symbol type. |
static GChart.AnnotationLocation |
DEFAULT_HOVER_LOCATION
The default hover feedback location used to position the hover feedback when the user hovers their mouse above a point on a curve (pie slices, and bar symbols have different defaults). |
static java.lang.String |
DEFAULT_HOVERTEXT_TEMPLATE
The default template string used to generate the hovertext displayed when the user hovers their mouse above a point on a curve (pie slices have a different default). |
static java.lang.String |
DEFAULT_LEGEND_BACKGROUND_COLOR
Default color of background of the chart legend |
static java.lang.String |
DEFAULT_LEGEND_BORDER_COLOR
Default color of border around the chart legend |
static java.lang.String |
DEFAULT_LEGEND_BORDER_STYLE
Default style of border around the chart legend |
static int |
DEFAULT_LEGEND_BORDER_WIDTH
Default width of border around the chart legend |
static int |
DEFAULT_LEGEND_FONTSIZE
The default fontsize of text that appears in the chart's legend (key). |
static int |
DEFAULT_LINE_FILL_SPACING
The default spacing between discrete, rectangular, elements used to simulate continuously connected lines between successive points on a curve that uses the LINE symbol type. |
static int |
DEFAULT_LINE_FILL_THICKNESS
The default thickness of connecting lines drawn on curves whose symbols have the LINE symbol type. |
static double |
DEFAULT_MAX_CANVAS_PIXELS
Default upper bound on the number of pixels any canvas widget used by GChart can have. |
static double |
DEFAULT_PIE_SLICE_FILL_SPACING
The default "spacing" between corresponding edges of the rectangular elements used to simulate continuous fill of pie slices. |
static int |
DEFAULT_PIE_SLICE_FILL_THICKNESS
The default "thickness" of the rectangular elements used to simulate continuous fill of pie slices. |
static GChart.AnnotationLocation |
DEFAULT_PIE_SLICE_HOVER_LOCATION
The default hover feedback location used by symbols when they have a symbol type of of the form PIE_SLICE_*. |
static java.lang.String |
DEFAULT_PIE_SLICE_HOVERTEXT_TEMPLATE
The default hovertext template used by symbols when they have a symbol type of of the form PIE_SLICE_*. |
static java.lang.String |
DEFAULT_PLOTAREA_BACKGROUND_COLOR
The default background color used for the chart's plot area if none is specified. |
static java.lang.String |
DEFAULT_PLOTAREA_BORDER_COLOR
The default border color used for the chart's plot area if none is specified. |
static java.lang.String |
DEFAULT_PLOTAREA_BORDER_STYLE
The default style of the border around the chart's plot area if none is specified. |
static int |
DEFAULT_PLOTAREA_BORDER_WIDTH
The default width of the border around the chart's plot area if none is specified. |
static java.lang.String |
DEFAULT_SYMBOL_BACKGROUND_COLOR
The default CSS background color used for symbols if none is specified. |
static java.lang.String[] |
DEFAULT_SYMBOL_BORDER_COLORS
The default CSS border colors used for symbols if none are specified. |
static java.lang.String |
DEFAULT_SYMBOL_BORDER_STYLE
The default CSS border style used for symbols if none is specified; this default is "solid". |
static int |
DEFAULT_SYMBOL_BORDER_WIDTH
The default CSS border width used for symbols if none is specified; this default is 1 pixel. |
static double |
DEFAULT_SYMBOL_FILL_SPACING
The default spacing between discrete, rectangular, elements used to simulate continuous graphical elements. |
static int |
DEFAULT_SYMBOL_FILL_THICKNESS
The default "thickness" of the rectangular elements used to simulate continuous graphical objects, such as connecting lines in line charts. |
static int |
DEFAULT_SYMBOL_HEIGHT
The default height (including borders) used for symbols if none is specified; this default is the same as for DEFAULT_SYMBOL_WIDTH |
static GChart.SymbolType |
DEFAULT_SYMBOL_TYPE
The default symbol type for curve if none is specified; this default is BOX_CENTER |
static int |
DEFAULT_SYMBOL_WIDTH
The default width (including borders) used for symbols if none is specified. |
static int |
DEFAULT_TICK_COUNT
The default number of tick marks on each Axis. |
static java.lang.String |
DEFAULT_TICK_LABEL_FONT_COLOR
The default color (a CSS color specification) of tick labels |
static java.lang.String |
DEFAULT_TICK_LABEL_FONT_STYLE
The default CSS font-style applied to tick labels |
static java.lang.String |
DEFAULT_TICK_LABEL_FONT_WEIGHT
The default CSS font-weight applied to tick labels |
static int |
DEFAULT_TICK_LABEL_FONTSIZE
The default fontsize (in pixels) of tick labels |
static java.lang.String |
DEFAULT_TICK_LABEL_FORMAT
The default GWT NumberFormat format string used to convert numbers to the text strings displayed as tick labels on X, Y, and Y2 axes. |
static int |
DEFAULT_TICK_LENGTH
The default length of tick marks, in pixels. |
static GChart.TickLocation |
DEFAULT_TICK_LOCATION
The default tick location. |
static int |
DEFAULT_TICK_THICKNESS
The default thickness of tick marks, in pixels. |
static int |
DEFAULT_TITLE_THICKNESS
The default thickness (height) of the rectangular region at the top of the chart allocated for the chart's title, per <br> or <li> delimited HTML line. |
static GChart.AnnotationLocation |
DEFAULT_VBAR_BASELINE_HOVER_LOCATION
The default location used to position the hover feedback when the user hovers their mouse above a point on a curve that uses a VBAR_BASELINE_* symbol type. |
static GChart.AnnotationLocation |
DEFAULT_VBARBOTTOM_HOVER_LOCATION
The default location used to position the hover feedback when the user hovers their mouse above a point on a curve that uses a VBAR_SOUTH* symbol type. |
static GChart.AnnotationLocation |
DEFAULT_VBARTOP_HOVER_LOCATION
The default location used to position the hover feedback when the user hovers their mouse above a point on a curve that uses a VBAR_NORTH* symbol type. |
static int |
DEFAULT_WIDGET_HEIGHT_UPPERBOUND
The default upper bound on the height of widgets used in annotations and tick labels that GChart will assume for centering and similar alignment purposes. |
static int |
DEFAULT_WIDGET_WIDTH_UPPERBOUND
The default upper bound on the width of widgets used in annotations and tick labels that GChart will assume for centering and similar alignment purposes. |
static int |
DEFAULT_X_CHARTSIZE
The default width of the area of the chart in which curves are displayed, in pixels. |
static int |
DEFAULT_Y_CHARTSIZE
The default height of the area of the chart in which curves are displayed, in pixels. |
static int |
NAI
In analogy to how it uses Double.NaN (Not a Number), GChart uses GChart.NAI (Not an Integer) to represent integers whose values have not been explicitly specified. |
static java.lang.String |
TRANSPARENT_BORDER_COLOR
Due to a well-known bug (see, for example, this explanation on Hedger Wang's blog), though white may not be black in IE6, transparent borders certainly are. |
static java.lang.String |
USE_CSS
A special value used to tell GChart that a property should be defined via CSS, not via an explicit Java API specification. |
static com.googlecode.gchart.client.GChart.YAxisId |
Y_AXIS
Keyword used to indicate that a curve should be displayed on the left y-axis. |
static com.googlecode.gchart.client.GChart.YAxisId |
Y2_AXIS
Keyword used to indicate that a curve should be displayed on the right (the so-called y2) y-axis. |
| Fields inherited from class com.google.gwt.user.client.ui.UIObject |
|---|
DEBUG_ID_PREFIX |
| Constructor Summary | |
|---|---|
GChart()
Convenience no-arg constructor equivalent to GChart(DEFAULT_X_CHARTSIZE,DEFAULT_Y_CHARTSIZE). |
|
GChart(int xChartSize,
int yChartSize)
Instantiates a GChart with a curve display region of the specified size. |
|
| Method Summary | |
|---|---|
com.google.gwt.event.shared.HandlerRegistration |
addClickHandler(com.google.gwt.event.dom.client.ClickHandler handler)
Adds an object to handle click events on this chart, that is, an object whose ClickHandler.onClick method will be called whenever the user clicks on this chart. |
void |
addCurve()
Adds a new curve to the chart, at the end of the current list of curves. |
void |
addCurve(int iCurve)
Adds a new curve to the chart, at the specified position in the curve sequence. |
com.google.gwt.event.shared.HandlerRegistration |
addDoubleClickHandler(com.google.gwt.event.dom.client.DoubleClickHandler handler)
Adds a DoubleClickEvent handler. |
com.google.gwt.event.shared.HandlerRegistration |
addMouseDownHandler(com.google.gwt.event.dom.client.MouseDownHandler handler)
Adds a MouseDownEvent handler. |
com.google.gwt.event.shared.HandlerRegistration |
addMouseMoveHandler(com.google.gwt.event.dom.client.MouseMoveHandler handler)
Adds a MouseMoveEvent handler. |
com.google.gwt.event.shared.HandlerRegistration |
addMouseOutHandler(com.google.gwt.event.dom.client.MouseOutHandler handler)
Adds a MouseOutEvent handler. |
com.google.gwt.event.shared.HandlerRegistration |
addMouseOverHandler(com.google.gwt.event.dom.client.MouseOverHandler handler)
Adds a MouseOverEvent handler. |
com.google.gwt.event.shared.HandlerRegistration |
addMouseUpHandler(com.google.gwt.event.dom.client.MouseUpHandler handler)
Adds a MouseUpEvent handler. |
com.google.gwt.event.shared.HandlerRegistration |
addMouseWheelHandler(com.google.gwt.event.dom.client.MouseWheelHandler handler)
Adds a MouseWheelEvent handler. |
void |
clearCurves()
Removes every curve this chart contains. |
static java.lang.String |
formatAsHovertext(java.lang.String plainTextLabel)
Convenience method that, given a plain text label, returns an HTML snippet appropriate for use as an argument to the setHovertextTemplate or setAnnotationText methods, that will display the plain text label with formatting appropriate for use with hovertext. |
java.lang.String |
getBackgroundColor()
Returns the background color of the chart as a whole. |
static java.lang.String |
getBlankImageURL()
Returns a URL that points to a 1 x 1 pixel blank image file GChart requires to render its charts without producing missing image icons. |
java.lang.String |
getBorderColor()
Returns the color of the border around the chart as a whole. |
java.lang.String |
getBorderStyle()
Returns the style of the border around the chart as a whole |
java.lang.String |
getBorderWidth()
Returns the width of the border around the chart as a whole |
static GChartCanvasFactory |
getCanvasFactory()
Returns the GChart class' canvas factory, or null if no canvas factory has been specified. |
com.google.gwt.user.client.ui.Widget |
getChartFootnotes()
Returns the previously specified chart footnotes widget. |
boolean |
getChartFootnotesLeftJustified()
Returns flag indicating if this chart's footnotes are left-justified or centered. |
int |
getChartFootnotesThickness()
Returns the thickness (height) of the rectangular region at the bottom of the chart allocated for footnotes. |
com.google.gwt.user.client.ui.Widget |
getChartTitle()
Returns the previously specified widget representing the chart's title. |
int |
getChartTitleThickness()
Returns the thickness (height) of the rectangular region at the top of the chart allocated for the title. |
boolean |
getClipToDecoratedChart()
Determines if this chart will clip any chart elements that extend beyond the bounds of the decorated chart. |
boolean |
getClipToPlotArea()
Returns true if graphical aspects of the chart that fall outside of the plot area are being clipped off, false otherwise. |
GChart.Curve.Point |
getClosestBrushTouchingPoint(int xPlotArea,
int yPlotArea)
Returns the point that would be touched if the mouse were moved to the given x,y plot-area pixel coordinates, or null if the moving the mouse to these coordinates would not have touched any points. |
static java.lang.Object |
getCurrentCurveData()
Returns a reference to the auxiliary data object of the curve that is currently being rendered by GChart. |
GChart.Curve |
getCurve()
Convenience method equivalent to getCurve(getNCurves()-1). |
GChart.Curve |
getCurve(int iCurve)
Returns a reference to the curve at the specified positional index. |
int |
getCurveIndex(GChart.Curve curve)
Returns the positional index (within this chart's list of curves) of the specified curve. |
java.lang.String |
getFontFamily()
Returns the font-family that is used, by default, for all textual annotations (tick labels, point lables, title, footnotes, legend labels, and axis labels) on that chart. |
java.lang.String |
getGridColor()
Returns CSS color specification for all gridlines, axes, and tickmarks. |
HoverParameterInterpreter |
getHoverParameterInterpreter()
Returns this GChart's hover parameter interpreter. |
boolean |
getHoverTouchingEnabled()
Is it possible to select points and have their hover annotations pop up, merely by "touching" them with the mouse-attached "brush"? |
double |
getInitialPieSliceOrientation()
Returns a previously specified initial pie slice orientation. |
com.google.gwt.user.client.ui.Widget |
getLegend()
Returns the developer-defined widget used for this chart's Legend. |
java.lang.String |
getLegendBackgroundColor()
Returns the background color of the chart's legend. |
java.lang.String |
getLegendBorderColor()
Returns the border color of the chart's legend. |
java.lang.String |
getLegendBorderStyle()
Returns the style of the chart's legend's border |
int |
getLegendBorderWidth()
Returns the width of the chart's legend's border |
java.lang.String |
getLegendFontColor()
Returns the color of the font used to display the labels within the legend (chart key) |
java.lang.String |
getLegendFontFamily()
Returns the font-family used to render this GChart's legend text. |
int |
getLegendFontSize()
Returns the CSS font size, in pixels, of text displayed in the chart's legend (also know as a chart's key). |
java.lang.String |
getLegendFontStyle()
Returns the font-style in which this GChart's legend text will be rendered. |
java.lang.String |
getLegendFontWeight()
Returns true if legend text will be rendered in a bold, or false if in normal, weight font. |
int |
getLegendThickness()
Returns the thickness (width) of the rectangular region to the right of the y2-axis label allocated for the chart legend. |
int |
getLegendXShift()
The amount, in pixels, the legend is shifted along the x axis from its base position. |
int |
getLegendYShift()
The amount, in pixels, the legend is shifted along the y axis from its base position. |
double |
getMaxCanvasPixels()
Returns the maximum number of pixels any canvas Widget used in GChart's rendering can have. |
int |
getNCurves()
Returns the number of curves on this chart. |
boolean |
getOptimizeForMemory()
Returns a flag that tells if GChart is configured to perform updates so that the chart uses less memory. |
java.lang.String |
getPadding()
Returns the CSS string that specifies the width of the padding between the chart and it's external border |
java.lang.String |
getPlotAreaBackgroundColor()
Returns the background color of the area of the chart in which symbols representing curve data are displayed |
java.lang.String |
getPlotAreaBorderColor()
Returns the border color of the area of the chart in which symbols representing curve data are displayed |
java.lang.String |
getPlotAreaBorderStyle()
Returns the style of the border around the area of the chart in which symbols representing curve data are displayed (the so-called plot area). |
int |
getPlotAreaBorderWidth()
Returns the width of the border around the area of the chart in which symbols representing curve data are displayed. |
java.lang.String |
getPlotAreaImageURL()
Returns the image URL that will be used to define the plot area's background the next time update is called. |
double |
getRenderPaddingFactor()
Returns the previously specified render padding factor. |
boolean |
getShowOffChartPoints()
Deprecated. Equivalent to !getClipToPlotArea(). Use that method instead. |
boolean |
getShowOffDecoratedChartGlyphs()
Deprecated. Equivalent to !getClipToDecoratedChart(). Use that method instead. |
GChart.Curve |
getTouchedCurve()
Returns the curve that the mouse "brush" is currently "touching" (the so-called "hovered over" point), or null if none. |
GChart.Curve.Point |
getTouchedPoint()
Returns the point that the mouse "brush" is currently "touching" (the so-called "hovered over" point), or null if none. |
GChart.Axis |
getXAxis()
Returns the x-axis associated with this chart. |
int |
getXChartSize()
Returns the number of x-pixels in the region of the chart used for curve display purposes. |
int |
getXChartSizeDecorated()
Returns the number of x-pixels reserved for the chart as a whole, including space reserved for decorations (title, footnotes, axis labels, ticks, tick labels, legend key, etc.). |
GChart.Axis |
getY2Axis()
Returns the y2-axis (right y axis) associated with this chart. |
GChart.Axis |
getYAxis()
Returns the (left) y-axis associated with this chart. |
int |
getYChartSize()
Returns the number of y-pixels in the region of the chart used for curve display purposes. |
int |
getYChartSizeDecorated()
Returns the number of y-pixels reserved for the chart as a whole, including space reserved for decorations (title, footnotes, axis labels, ticks, tick labels, etc.). |
boolean |
hasY2Axis()
Determines if this chart has a "y2" (right) y-axis. |
boolean |
hasYAxis()
Determines if this chart has an ordinary, or left, y-axis. |
boolean |
isLegendVisible()
Determines if the legend of this chart is visible. |
boolean |
isUpdateNeeded()
Is the in-browser rendition of the chart inconsistent with the current chart specs? In other words, is a call to GChart's update method needed to bring the browser's display into agreement with current chart specs? |
void |
removeCurve(GChart.Curve curve)
Removes the given curve from this GChart. |
void |
removeCurve(int iCurve)
Removes the curve at the specified positional index. |
void |
setBackgroundColor(java.lang.String cssColor)
Specifies the background color of the chart as a whole. |
static void |
setBlankImageURL(java.lang.String blankImageURL)
Specifies a URL that points to the transparent, 1 x 1 pixel, "blank GIF" that GChart uses in order to render your chart without adding spurious "missing image" icons to it. |
void |
setBorderColor(java.lang.String cssColor)
Specifies the color of the border around the chart as a whole. |
void |
setBorderStyle(java.lang.String borderStyle)
Sets style of the border around the chart as a whole. |
void |
setBorderWidth(java.lang.String cssWidth)
Specifies the width of the border around the chart as a whole. |
void |
setCanvasExpansionFactors(double widthExpansionFactor,
double heightExpansionFactor)
Specifies the fractional amount that the default width and height of each canvas used to render this chart will be increased. |
static void |
setCanvasFactory(GChartCanvasFactory factory)
Tells GChart how to create the canvas widgets it needs (specifically, widgets that implement GChart's GChartCanvasLite interface) to render your charts using an external vector graphics library. |
void |
setChartFootnotes(java.lang.String html)
Convenience method equivalent to setChartFootnotes(new HTML(html)) . |
void |
setChartFootnotes(com.google.gwt.user.client.ui.Widget chartFootnotes)
Sets widget that appears just below the chart. |
void |
setChartFootnotesLeftJustified(boolean footnotesLeftJustified)
Defines if this chart's footnotes are left justified, or horizontally centered across the bottom edge of the chart. |
void |
setChartFootnotesThickness(int thickness)
Sets the thickness (height) of the rectangular region at the bottom of the chart allocated for the footnotes. |
void |
setChartSize(int xChartSize,
int yChartSize)
Convenience method equivalent to setXChartSize(xChartSize); setYChartSize(yChartSize). |
void |
setChartTitle(java.lang.String html)
Convenience method equivalent to setChartTitle(new HTML(html)). |
void |
setChartTitle(com.google.gwt.user.client.ui.Widget chartTitle)
Specifies the widget that appears centered just above the chart. |
void |
setChartTitleThickness(int thickness)
Sets the thickness (height) of the rectangular region at the top of the chart allocated for the title. |
void |
setClipToDecoratedChart(boolean clipToDecoratedChart)
Specifies if this chart will clip any rendered chart elements (including hover selection feedback and popup annotations) that extends beyond the bounds of the decorated chart. |
void |
setClipToPlotArea(boolean clipToPlotArea)
Specifies if rendered graphics falling outside the plot area will be clipped off. |
static void |
setDefaultSymbolBorderColors(java.lang.String[] defaultBorderColors)
Sets the symbol border colors that are used by default for newly created curves. |
void |
setFontFamily(java.lang.String fontFamily)
Specifies the font-family that is used, by default, for all textual annotations (tick labels, point labels, title, footnotes, legend labels, and axis labels) on this chart. |
void |
setGridColor(java.lang.String cssColor)
Specifies the single color used for all gridlines, axes lines, and tick marks. |
void |
setHoverParameterInterpreter(HoverParameterInterpreter hpi)
Defines this GChart's hover parameter interpreter. |
void |
setHoverTouchingEnabled(boolean hoverTouchingEnabled)
Specifies if merely hovering over a point is sufficient to select it and display its hover annotation (true), or if an actual click is needed (false). |
void |
setInitialPieSliceOrientation(double orientation)
Sets the default initial orientation for pie slices. |
void |
setLegend(com.google.gwt.user.client.ui.Widget legend)
This method allows you to replace GChart's legend with a Widget you create to represent the chart legend. |
void |
setLegendBackgroundColor(java.lang.String cssColor)
Sets the background color of the chart's legend. |
void |
setLegendBorderColor(java.lang.String cssColor)
Sets the border color of the chart's legend. |
void |
setLegendBorderStyle(java.lang.String borderStyle)
Sets style of the border around the chart's legend (key). |
void |
setLegendBorderWidth(int width)
Sets the width of the chart legend's border. |
void |
setLegendFontColor(java.lang.String cssColor)
Specifies the color of the legend's font. |
void |
setLegendFontFamily(java.lang.String cssFontFamily)
Specifies the CSS font-family of the font used to render the legend's labels. |
void |
setLegendFontSize(int legendFontSize)
Specifies the CSS font size, in pixels, of text displayed in the chart's legend (also know as a chart's key). |
void |
setLegendFontStyle(java.lang.String cssStyle)
Specifies the cssStyle of the font used to render the legend's labels. |
void |
setLegendFontWeight(java.lang.String cssWeight)
Specifies the weight of the font used in the labels of the legend. |
void |
setLegendLocation(GChart.LegendLocation legendLocation)
Specifies the position of the legend on the chart. |
void |
setLegendThickness(int legendThickness)
Sets the thickness (width) of the rectangular region at the right or left of the chart allocated for the legend key. |
void |
setLegendVisible(boolean isLegendVisible)
Specifies if the legend is to be visible on this chart. |
void |
setLegendXShift(int xShift)
Specifies the number of pixels (along the x-axis) to move the legend from its default, LegendLocation-defined, position. |
void |
setLegendYShift(int yShift)
Specifies the number of pixels (along the y-axis) to move the legend from its default, LegendLocation-defined, position. |
void |
setMaxCanvasPixels(double maxCanvasPixels)
Sets the upper bound on the number of pixels any canvas widget used by GChart can have. |
void |
setOptimizeForMemory(boolean optimizeForMemory)
By default, this property is false, which means that GChart will retain no-longer-needed Image and Grid widgets (plus any user object references associated with those widgets, such as those created via the setAnnotationText and setAnnotationWidget methods) between updates in the expectation that they may be needed by future updates. |
void |
setPadding(java.lang.String cssPadding)
Specifies the amount of padding to add just inside of the chart's border, as a CSS padding specification string. |
void |
setPlotAreaBackgroundColor(java.lang.String cssColor)
Specifies the background color of the area of the chart in which symbols representing curve data are displayed |
void |
setPlotAreaBorderColor(java.lang.String cssColor)
Specifies the color of the border around the area of the chart in which symbols representing curve data are displayed. |
void |
setPlotAreaBorderStyle(java.lang.String borderStyle)
Sets style of the border around the chart's plot area (the rectangular area where the curves are drawn). |
void |
setPlotAreaBorderWidth(int width)
Specifies the width of the border around the area of the chart in which symbols representing curve data are displayed. |
void |
setPlotAreaImageURL(java.lang.String imageURL)
Sets the image URL that defines the background of the GChart plot area. |
void |
setRenderPaddingFactor(double renderPaddingFactor)
Defines a region around the perimeter of the currently visible area of the chart that will be rendered, even though it cannot at present be seen (due to clipping). |
void |
setShowOffChartPoints(boolean showOffChartPoints)
Deprecated. Equivalent to setClipToPlotArea(!showOffChartPoints) . Use that method instead. As of GChart 2.5, the clip-to-plot-area algorithm no longer drops the entire symbol if it's x,y coordinates are outside of the plot area; instead, it clips them off in the traditional "overflow: hidden" manner. Though unlikely you would need to, there is no easy way to recreate the previous behavior. This change was made so that both rectangular HTML and continuous, canvas-rendered chart elements would be clipped in a consistent and sensible way. |
void |
setShowOffDecoratedChartGlyphs(boolean showOffDecoratedChartGlyphs)
Deprecated. Equivalent to setClipToDecoratedChart(!showOffDecoratedChart), please use that method instead. |
void |
setXChartSize(int xChartSize)
Sets the number of pixels, in the horizontal dimension, available for curve display. |
void |
setYChartSize(int yChartSize)
Sets the number of pixels, in the vertical dimension, available for curve display. |
void |
touch(GChart.Curve.Point pointToTouch)
Simulates the user "touching" a point with the mouse, by performing those operations that occur when the user "hovers over" the specified point. |
void |
update()
Updates the chart, using an appropriate default touched point update option, depending on if hover touching is enabled or not. |
void |
update(GChart.TouchedPointUpdateOption option)
Builds a chart that reflects current user-specified chart specs (curve data, symbol choices, etc.) |
| Methods inherited from class com.google.gwt.user.client.ui.Composite |
|---|
isAttached, onBrowserEvent |
| Methods inherited from class com.google.gwt.user.client.ui.Widget |
|---|
fireEvent, getLayoutData, getParent, removeFromParent, setLayoutData, sinkEvents |
| Methods inherited from class com.google.gwt.user.client.ui.UIObject |
|---|
addStyleDependentName, addStyleName, ensureDebugId, ensureDebugId, getAbsoluteLeft, getAbsoluteTop, getElement, getOffsetHeight, getOffsetWidth, getStyleName, getStylePrimaryName, getTitle, isVisible, isVisible, removeStyleDependentName, removeStyleName, setHeight, setPixelSize, setSize, setStyleName, setStylePrimaryName, setTitle, setVisible, setVisible, setWidth, toString, unsinkEvents |
| Methods inherited from class java.lang.Object |
|---|
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Methods inherited from interface com.google.gwt.event.shared.HasHandlers |
|---|
fireEvent |
| Field Detail |
|---|
public static final int DEFAULT_ANNOTATION_FONTSIZE
Point.setFontSize,
Constant Field Valuespublic static final int DEFAULT_BRUSH_HEIGHT
setBrushHeight,
setBrushWidth,
DEFAULT_BRUSH_WIDTH,
Constant Field Valuespublic static final int DEFAULT_BRUSH_WIDTH
setBrushHeight,
setBrushWidth,
DEFAULT_BRUSH_HEIGHT,
Constant Field Valuespublic static final java.lang.String DEFAULT_LEGEND_BORDER_COLOR
setLegendBorderColor,
Constant Field Valuespublic static final int DEFAULT_LEGEND_BORDER_WIDTH
setLegendBorderWidth,
Constant Field Valuespublic static final java.lang.String DEFAULT_LEGEND_BORDER_STYLE
setLegendBorderStyle,
Constant Field Valuespublic static final java.lang.String DEFAULT_LEGEND_BACKGROUND_COLOR
setLegendBackgroundColor,
Constant Field Valuespublic static final java.lang.String DEFAULT_FONT_COLOR
setLegendFontColor,
setTickLabelFontColor,
setAnnotationFontColor,
Constant Field Valuespublic static final java.lang.String DEFAULT_FONT_FAMILY
Chosen to be the same font-family as that used in GWT's standard CSS stylesheet ("theme").
setLegendFontFamily,
setTickLabelFontFamily,
setAnnotationFontFamily,
Constant Field Valuespublic static final java.lang.String DEFAULT_FONT_STYLE
setLegendFontStyle,
setTickLabelFontStyle,
setAnnotationFontStyle,
Constant Field Valuespublic static final java.lang.String DEFAULT_FONT_WEIGHT
setLegendFontWeight,
setTickLabelFontWeight,
setAnnotationFontWeight,
Constant Field Valuespublic static final java.lang.String DEFAULT_HOVERTEXT_TEMPLATE
setHovertextTemplate,
DEFAULT_PIE_SLICE_HOVERTEXT_TEMPLATEpublic static final GChart.AnnotationLocation DEFAULT_HOVER_LOCATION
setHoverLocation,
DEFAULT_PIE_SLICE_HOVER_LOCATION,
DEFAULT_VBAR_BASELINE_HOVER_LOCATION,
DEFAULT_VBARBOTTOM_HOVER_LOCATION,
DEFAULT_VBARTOP_HOVER_LOCATION,
DEFAULT_HBAR_BASELINE_HOVER_LOCATION,
DEFAULT_HBARLEFT_HOVER_LOCATION,
DEFAULT_HBARRIGHT_HOVER_LOCATIONpublic static final int DEFAULT_LEGEND_FONTSIZE
setTickLabelFontSize,
getXAxis,
getYAxis,
getY2Axis,
Constant Field Valuespublic static final java.lang.String DEFAULT_PLOTAREA_BACKGROUND_COLOR
setPlotAreaBackgroundColor,
Constant Field Valuespublic static final java.lang.String DEFAULT_PLOTAREA_BORDER_COLOR
setPlotAreaBorderColor,
Constant Field Valuespublic static final java.lang.String DEFAULT_PLOTAREA_BORDER_STYLE
setPlotAreaBorderStyle,
Constant Field Valuespublic static final int DEFAULT_PLOTAREA_BORDER_WIDTH
setPlotAreaBorderWidth,
Constant Field Valuespublic static final java.lang.String DEFAULT_SYMBOL_BACKGROUND_COLOR
getSymbol,
setBackgroundColor,
Constant Field Valuespublic static final java.lang.String[] DEFAULT_SYMBOL_BORDER_COLORS
getSymbol,
setBorderColorpublic static final java.lang.String DEFAULT_SYMBOL_BORDER_STYLE
getSymbol,
setBorderStyle,
Constant Field Valuespublic static final int DEFAULT_SYMBOL_BORDER_WIDTH
getSymbol,
setBorderWidth,
Constant Field Valuespublic static final double DEFAULT_SYMBOL_FILL_SPACING
getSymbol,
setFillSpacing,
setFillThickness,
DEFAULT_BAR_FILL_SPACING,
DEFAULT_LINE_FILL_SPACING,
Constant Field Valuespublic static final int DEFAULT_SYMBOL_FILL_THICKNESS
Since this default thickness is 0 px, this implies that, except for pie slices and lines, no such continuous fill elements are generated by default. For example, if you want to have dotted connecting lines drawn between individual data points represented using the BOX_CENTER symbol type, you must explicitly specify a positive fill thickness (for solid connecting lines, the LINE symbol is usually far more efficient than using a fill thickness of 1px with the BOX_CENTER symbol).
DEFAULT_PIE_SLICE_FILL_THICKNESS,
DEFAULT_LINE_FILL_THICKNESS,
getSymbol,
setFillSpacing,
setFillThickness,
Constant Field Valuespublic static final double DEFAULT_BAR_FILL_SPACING
getSymbol,
setFillSpacing,
setFillThickness,
DEFAULT_SYMBOL_FILL_SPACING,
Constant Field Valuespublic static final int DEFAULT_LINE_FILL_THICKNESS
DEFAULT_SYMBOL_FILL_THICKNESS,
getSymbol,
setFillSpacing,
setFillThickness,
Constant Field Valuespublic static final int DEFAULT_LINE_FILL_SPACING
getSymbol,
setFillSpacing,
setFillThickness,
DEFAULT_SYMBOL_FILL_SPACING,
Constant Field Valuespublic static final double DEFAULT_PIE_SLICE_FILL_SPACING
DEFAULT_SYMBOL_FILL_SPACING,
DEFAULT_PIE_SLICE_FILL_THICKNESS,
getSymbol,
setFillSpacing,
setFillThickness,
Constant Field Valuespublic static final int DEFAULT_PIE_SLICE_FILL_THICKNESS
DEFAULT_SYMBOL_FILL_THICKNESS,
DEFAULT_LINE_FILL_THICKNESS,
getSymbol,
setFillSpacing,
setFillThickness,
Constant Field Valuespublic static final java.lang.String DEFAULT_PIE_SLICE_HOVERTEXT_TEMPLATE
setHovertextTemplate,
PIE_SLICE_OPTIMAL_SHADING,
DEFAULT_HOVERTEXT_TEMPLATEpublic static final GChart.AnnotationLocation DEFAULT_PIE_SLICE_HOVER_LOCATION
setHoverLocation,
DEFAULT_HOVER_LOCATIONpublic static final int DEFAULT_SYMBOL_HEIGHT
getSymbol,
setHeight,
DEFAULT_SYMBOL_WIDTH,
Constant Field Valuespublic static final GChart.SymbolType DEFAULT_SYMBOL_TYPE
BOX_CENTER,
setSymbolTypepublic static final int DEFAULT_SYMBOL_WIDTH
getSymbol,
setWidth,
DEFAULT_SYMBOL_WIDTH,
Constant Field Valuespublic static final int DEFAULT_TICK_COUNT
setTickCount,
Constant Field Valuespublic static final java.lang.String DEFAULT_TICK_LABEL_FONT_COLOR
setTickLabelFontColor,
getXAxis,
getYAxis,
getY2Axis,
Constant Field Valuespublic static final java.lang.String DEFAULT_TICK_LABEL_FONT_STYLE
setTickLabelFontStyle,
getXAxis,
getYAxis,
getY2Axis,
Constant Field Valuespublic static final java.lang.String DEFAULT_TICK_LABEL_FONT_WEIGHT
setTickLabelFontWeight,
getXAxis,
getYAxis,
getY2Axis,
Constant Field Valuespublic static final int DEFAULT_TICK_LABEL_FONTSIZE
setTickLabelFontSize,
getXAxis,
getYAxis,
getY2Axis,
Constant Field Valuespublic static final java.lang.String DEFAULT_TICK_LABEL_FORMAT
setTickLabelFormat,
getXAxis,
getYAxis,
getY2Axis,
Constant Field Valuespublic static final int DEFAULT_TICK_LENGTH
setTickLength,
Constant Field Valuespublic static final GChart.TickLocation DEFAULT_TICK_LOCATION
setTickLocationpublic static final int DEFAULT_TICK_THICKNESS
setTickThickness,
Constant Field Valuespublic static final GChart.AnnotationLocation DEFAULT_VBAR_BASELINE_HOVER_LOCATION
setHoverLocation,
DEFAULT_HOVER_LOCATIONpublic static final GChart.AnnotationLocation DEFAULT_VBARBOTTOM_HOVER_LOCATION
setHoverLocation,
DEFAULT_HOVER_LOCATIONpublic static final GChart.AnnotationLocation DEFAULT_VBARTOP_HOVER_LOCATION
setHoverLocation,
DEFAULT_HOVER_LOCATIONpublic static final GChart.AnnotationLocation DEFAULT_HBAR_BASELINE_HOVER_LOCATION
setHoverLocation,
DEFAULT_HOVER_LOCATIONpublic static final GChart.AnnotationLocation DEFAULT_HBARLEFT_HOVER_LOCATION
setHoverLocation,
DEFAULT_HOVER_LOCATIONpublic static final GChart.AnnotationLocation DEFAULT_HBARRIGHT_HOVER_LOCATION
setHoverLocation,
DEFAULT_HOVER_LOCATIONpublic static final double DEFAULT_MAX_CANVAS_PIXELS
setMaxCanvasPixels,
Constant Field Valuespublic static final int DEFAULT_WIDGET_WIDTH_UPPERBOUND
setAnnotationWidget,
addTick,
Constant Field Valuespublic static final int DEFAULT_WIDGET_HEIGHT_UPPERBOUND
setAnnotationWidget,
addTick,
Constant Field Valuespublic static final int DEFAULT_X_CHARTSIZE
public static final int DEFAULT_Y_CHARTSIZE
public static final int NAI
public static final java.lang.String TRANSPARENT_BORDER_COLOR
To make it easy for you to eliminate such problems, and obtain a consistently behaving transparent-border behavior cross-browser, this special GChart-only "color" (recognized by all GChart border color related methods except GChart.setBorderColor) causes GChart to emulate a transparent border by eliminating the border entirely (setting it's width to 0) and changing the size and position of the element so as to make it look like the border is still "taking up space".
Note:The GChart.setBorderColor method, which sets the color of the border around the entire chart, does not support this keyword because GChart's transparent border emulation relies on changing the size of, and shifting the position of, the transparently bordered element. But, the position of the GChart as a whole is determined not by GChart, but by the enclosing page. Well-known CSS tricks, such as described in the "hedgerwow" link above, can be used if you need a truely transparent border around the entire chart. Or, just fake it by setting the border color to equal the background color of the containing page.
This differs from setting the border color to "transparent" (which you can still do should you need the "standard non-standard" transparent border color behavior) in subtle ways that can matter in special cases. For example, because the element is smaller than it is with "transparent", if you draw your symbols outside the chart rectangle, GChart will not be able to track the mouse moves inside the transparent region (yes, this is a fine point, but there could be other differences I'm not aware of). In almost every other case I can think of, though, setting the border color to this special keyword instead of "transparent" will be the simplest way to eliminate these inconsistent transparent border problems from your charts.
setBorderColorpublic static final java.lang.String USE_CSS
This value is mainly used by GChart's "CSS convenience methods" which make it possible to use the Java API to specify certain properties of a GChart that can also be specified via CSS. When the value of the Java property is set to USE_CSS GChart ignores the API specification and allows the standard "CSS cascade" to define the property. The discussion below elaborates on why GChart supports CSS convenience methods, and how the USE_CSS keyword fits into that support.
CSS Convenience Methods and the GChart.USE_CSS keywordLike all GWT Widgets, a GChart is both an object in a Java application, and an HTML element in a web page.
This duality naturally divides the properties of a GChart into three categories:
- Those you can access only via the Java API.
- Those you can access only via CSS and the DOM.
- Those you can access both ways.
I've used the following criteria to determine the access method appropriate for a given GChart property:
- Those properties that mainly define the chart itself--independent of its relationship to any containing web page--are exclusively accessed via the Java API.
For example, the x,y data values of a curve have everything to do with the chart itself and nothing to do with the enclosing web page, so all the defining x,y data of a curve can only be accessed via the Java API.
- Those properties that mainly define how the chart fits into the enclosing web page and have nothing to do with the chart itself are accessed exclusively via CSS stylesheets or the GWT DOM class.
For example, how big of a margin should be placed around a GChart is only about how the GChart fits into the enclosing web page, so you must define a GChart's margins using a CSS stylesheet (or via the GWT DOM class)--there is no GChart.setMargin method.
- Finally, those properties that, in some situations are best viewed as part of the chart itself, and in other situations as defining how the chart fits into the enclosing web page can be accessed either via the Java API, or via CSS/DOM.
For example, if you are focused on assuring that the chart has a the same border as every other element on the page, the border around the chart as a whole can be viewed as relating to how the chart fits into the enclosing web page. On the other hand, if you are focused on assuring that, like the frame around a picture, the border looks good around that particular chart, it makes more sense to view it as a part of the chart itself.
The Java API methods for GChart properties in this third category are known as "CSS convenience methods" because, though you could do the same thing by exploiting the "GChart as HTML element" perspective, these methods save you the trouble of looking up CSS syntax, splitting up your chart's specification between Java code and a CSS stylesheet, invoking a rather hard-to-remember method call in the GWT DOM class, etc.
Specifications made via the GChart Java API always take precedence over those made via stylesheets or the DOM class. To instruct GChart that you want one of these properties to be defined via CSS or the DOM, set the associated Java API property to the special value GChart.USE_CSS.
Fortunately, since USE_CSS is the default value for every one of these CSS convenience properties, if you never use the Java API to set them, you can use CSS to control them just as you would for a GWT widget that did not support convenience properties. Unfortunately, these CSS defaults rarely produce a great looking chart out of the box; the example CSS snippet below defines all of these convenience properties and attaches them to GChart's default CSS selector (aka stylename) in a way that I think looks better. A comment to the right of each line contains the corresponding CSS convenience-method call that has the same effect.
.gchart-GChart { background-color: #DDF; /* setBackgroundColor("#DDF"); */ border-width: 1px; /* setBorderWidth("1px"); */ border-color: black; /* setBorderColor("black"); */ border-style: solid; /* setBorderStyle("solid"); */ }Note that certain CSS convenience methods that could in principle have been added, such as those for defining the background image of a chart, were omitted because I thought they would almost never be used. Of course, you can always access these CSS properties "the old fashioned way" (via a CSS specification or methods of the GWT DOM class).
setBorderColor,
setBorderStyle,
setBackgroundColor,
setBorderWidth,
Constant Field Valuespublic static final com.googlecode.gchart.client.GChart.YAxisId Y_AXIS
Y2_AXIS,
setYAxispublic static final com.googlecode.gchart.client.GChart.YAxisId Y2_AXIS
Y_AXIS,
setYAxispublic static final java.lang.String DEFAULT_BLANK_IMAGE_URL
setBlankImageURL,
Constant Field Valuespublic static final java.lang.String DEFAULT_BLANK_IMAGE_URL_FULLPATH
Convenience constant equal to:
GWT.getModuleBaseURL() + GChart.DEFAULT_BLANK_IMAGE_URL
setBlankImageURLpublic static final java.lang.String DEFAULT_GRID_COLOR
setGridColor,
Constant Field Valuespublic static final int DEFAULT_FOOTNOTES_THICKNESS
setChartFootnotesThickness,
Constant Field Valuespublic static final int DEFAULT_TITLE_THICKNESS
setChartTitleThickness,
Constant Field Values| Constructor Detail |
|---|
public GChart(int xChartSize,
int yChartSize)
xChartSize - the width of the curve display region, in pixels.yChartSize - the height of the curve display region, in pixels.setXChartSize,
setYChartSize,
setChartSizepublic GChart()
GChart(int,int)| Method Detail |
|---|
public static void setCanvasFactory(GChartCanvasFactory factory)
You must define a class that implements GChartCanvasFactory and then pass an instance of that class to this method, if you want to have the fast, crisply drawn connecting lines, polygonal areas, and 2-D pie slices that only a vector graphics library can provide.
Note: If all of your charts only have rectangular elements (e.g. bar charts) GChart will continue to render those charts using HTML elements, even if a canvas factory is provided. Thus, there is no point to defining a canvas factory if all you use GChart for is bar charts, scatter plots without connecting lines between each point, banded-fill pie slices, and so on.
On the other hand, if you need continously connected lines, solid-fill pie slices, or solid-fill area charts (all of which will also need a setFillSpacing(0) to specify continuous filling) you will gain substantial performance/quality improvements if you add a canvas factory.
In detail, to exploit browser-based vector graphics (Mozilla's canvas, IE's VML, etc.) rendering in your charts, you must:
<inherits name='com.google.gwt.widgetideas.GWTCanvas' />To make this work, we also had to add the gwt-incubator.jar file (which contains GWTCanvas) to our build path via Eclipse's "Configure Build Path..." command and to the libraries listed in the classpath=... line of our ant build script's java task.
For more on the GWTCanvas widget, see the GWTCanvas Wiki page within the GWT incubator site.
package com.googlecode.gchart.gcharttestapp.client;
import com.googlecode.gchart.client.GChartCanvasLite;
import com.google.gwt.widgetideas.graphics.client.GWTCanvas;
import com.google.gwt.widgetideas.graphics.client.Color;
public class GWTCanvasBasedCanvasLite
extends GWTCanvas implements GChartCanvasLite {
// GChartCanvasLite requires CSS/RGBA color strings, but
// GWTCanvas uses its own Color class instead, so we wrap:
public void setStrokeStyle(String cssColor) {
// Sharp angles of default MITER can overwrite adjacent pie slices
setLineJoin(GWTCanvas.ROUND);
setStrokeStyle(new Color(cssColor));
}
public void setFillStyle(String cssColor) {
setFillStyle(new Color(cssColor));
}
// Note: all other GChartCanvasLite methods (lineTo, moveTo,
// arc, etc.) are directly inherited from GWTCanvas, so no
// wrapper methods are needed.
}
package com.googlecode.gchart.gcharttestapp.client;
import com.googlecode.gchart.client.GChartCanvasLite;
import com.googlecode.gchart.client.GChartCanvasFactory;
public class GWTCanvasBasedCanvasFactory
implements GChartCanvasFactory {
public GChartCanvasLite create() {
GChartCanvasLite result = new GWTCanvasBasedCanvasLite();
return result;
}
}
static {
GChart.setCanvasFactory(new GWTCanvasBasedCanvasFactory());
}
Because the above line essentially completes the definition of the GChart class (and thus should only be executed once per application) a good home for it is in a static initializer, as shown above. I recommend placing that initializer within your application's EntryPoint class.
Note: To make things a bit simpler for you, the following code combines steps 2, 3, and 4 into a single chunk of easily pasted boilerplate:
// Required imports:
import com.googlecode.gchart.client.GChart;
import com.googlecode.gchart.client.GChartCanvasFactory;
import com.googlecode.gchart.client.GChartCanvasLite;
import com.google.gwt.widgetideas.graphics.client.Color;
import com.google.gwt.widgetideas.graphics.client.GWTCanvas;
// Paste these lines into the top-level GWT class that kicks off your
// application (the one that "implements EntryPoint"):
static final class GWTCanvasBasedCanvasLite
extends GWTCanvas implements GChartCanvasLite {
// GChartCanvasLite requires CSS/RGBA color strings, but
// GWTCanvas uses its own Color class instead, so we wrap:
public void setStrokeStyle(String cssColor) {
// Sharp angles of default MITER can overwrite adjacent pie slices
setLineJoin(GWTCanvas.ROUND);
setStrokeStyle(new Color(cssColor));
}
public void setFillStyle(String cssColor) {
setFillStyle(new Color(cssColor));
}
// Note: all other GChartCanvasLite methods (lineTo, moveTo,
// arc, etc.) are directly inherited from GWTCanvas, so no
// wrapper methods are needed.
}
static final class GWTCanvasBasedCanvasFactory
implements GChartCanvasFactory {
public GChartCanvasLite create() {
GChartCanvasLite result = new GWTCanvasBasedCanvasLite();
return result;
}
}
// This line "teaches" GChart how to create the canvas
// widgets it needs to render any continuous,
// non-rectangular, chart aspects (solid fill pie slices,
// continously connected lines, etc.) clearly and
// efficiently. It's generally best to do this exactly once,
// when your entire GWT application loads.
static {
GChart.setCanvasFactory(new GWTCanvasBasedCanvasFactory());
}
To see the above boilerplate within a working example application, follow the link at the bottom of GChart's live demo page to examine its EntryPoint class' code.
GChart's mixed canvas and HTML rendering
The rendering mode (HTML-only or HTML+canvas) for each curve is defined by
if a canvas factory is available and if that curve uses the special
setFillSpacing(0) setting (meaning: "continuously filled"). So, to
force any curve to be only HTML rendered, simply set this fill spacing to a
value greater than 0.
HTML rendering offers some features not available with canvas rendering.
For example, only HTML-rendered curves can overwrite the enclosing page
without monopolizing mouse events within that curve's bounding rectangle,
and only HTML-rendered curves can define their "fill" via an image. HTML
rendered curves can sometimes even be more memory-efficent, provided the
number of pixels greatly exceeds the number of HTML elements. And the HTML
only rendering option provides a useful least common denominator/fall-back,
supported by even the most obscure browsers.
Note that the internal curves that GChart uses to render tick marks,
gridlines, etc. are never canvas rendered, because they only involve
vertical or horizontal rectangles, which GChart always renders with HTML.
Even with an external canvas factory enabled, many aspects of your chart
will remain HTML-rendered. In general, GChart only renders non-rectangular,
"continuously filled" aspects of your chart using canvas. Other aspects,
such as the bars on a bar chart, or the individual rectangular point
markers on a line chart, as well as all chart text, will remain HTML
rendered.
Finally, if you are content with GChart's built-in HTML-based rendering, or if your charts only use rectangular elements (e.g. bar charts) you don't need to bother with any of the steps listed above. Your charts will then only depend on the standard GWT distribution and the 3,000 or so lines of pure GWT Java that implement GChart.
Important: GChart only uses your external canvas facility to draw a chart's non-rectangular aspects. Given how GChart works, a curve can only have non-rectangular aspects if setFillSpacing has been set to 0 (which implies "continuous filling"), and setFillThickness has been set to a value > 0. If you are not seeing crisp, canvas-rendered area, line, or pie charts, be sure to check these two settings on the curves in question.
GChartCanvasFactory,
GChartCanvasLite,
getCanvasFactory,
setFillSpacing,
setFillThicknesspublic static GChartCanvasFactory getCanvasFactory()
setCanvasFactorypublic com.google.gwt.event.shared.HandlerRegistration addClickHandler(com.google.gwt.event.dom.client.ClickHandler handler)
When implementing a class that handles GChart click events, you'll need to know the following facts:
// Deletes the clicked-on curve
public void onClick(ClickEvent event) {
GChart theGChart = (GChart) event.getSource();
GChart.Curve c = theGChart.getTouchedCurve();
if (null != c) {
theGChart.removeCurve(c);
// what you see in browser won't change without an update
theGChart.update();
}
}
The editable pie chart example on the GChart live demo page illustrates how to use this method to launch a popup modal DialogBox whenever the user clicks on a point, and how to change the selected point from within that dialog by using GChart's touch method.
For a much simpler example that lets the user delete points by clicking on them, see the Chart Gallery's GChartExample18a.
addClickHandler in interface com.google.gwt.event.dom.client.HasClickHandlershandler - the click handler that will handle click events on this chart.
getTouchedPoint,
getTouchedCurve,
touch,
isUpdateNeededpublic com.google.gwt.event.shared.HandlerRegistration addDoubleClickHandler(com.google.gwt.event.dom.client.DoubleClickHandler handler)
See addClickHandler for GChart-specific information you will need to properly handle the event.
addDoubleClickHandler in interface com.google.gwt.event.dom.client.HasDoubleClickHandlershandler - the double click handler
addClickHandlerpublic com.google.gwt.event.shared.HandlerRegistration addMouseDownHandler(com.google.gwt.event.dom.client.MouseDownHandler handler)
See addClickHandler for GChart-specific information you will need to properly handle the event.
addMouseDownHandler in interface com.google.gwt.event.dom.client.HasMouseDownHandlershandler - the mouse down handler
addClickHandlerpublic com.google.gwt.event.shared.HandlerRegistration addMouseMoveHandler(com.google.gwt.event.dom.client.MouseMoveHandler handler)
See addClickHandler for GChart-specific information you will need to properly handle the event.
addMouseMoveHandler in interface com.google.gwt.event.dom.client.HasMouseMoveHandlershandler - the mouse move handler
addClickHandlerpublic com.google.gwt.event.shared.HandlerRegistration addMouseOutHandler(com.google.gwt.event.dom.client.MouseOutHandler handler)
See addClickHandler for GChart-specific information you will need to properly handle the event.
addMouseOutHandler in interface com.google.gwt.event.dom.client.HasMouseOutHandlershandler - the mouse out handler
addClickHandlerpublic com.google.gwt.event.shared.HandlerRegistration addMouseOverHandler(com.google.gwt.event.dom.client.MouseOverHandler handler)
See addClickHandler for GChart-specific information you will need to properly handle the event.
addMouseOverHandler in interface com.google.gwt.event.dom.client.HasMouseOverHandlershandler - the mouse over handler
addClickHandlerpublic com.google.gwt.event.shared.HandlerRegistration addMouseUpHandler(com.google.gwt.event.dom.client.MouseUpHandler handler)
See addClickHandler for GChart-specific information you will need to properly handle the event.
addMouseUpHandler in interface com.google.gwt.event.dom.client.HasMouseUpHandlershandler - the mouse up handler
addClickHandlerpublic com.google.gwt.event.shared.HandlerRegistration addMouseWheelHandler(com.google.gwt.event.dom.client.MouseWheelHandler handler)
See addClickHandler for GChart-specific information you will need to properly handle the event.
addMouseWheelHandler in interface com.google.gwt.event.dom.client.HasMouseWheelHandlershandler - the mouse wheel handler
addClickHandlerpublic void addCurve()
getCurve,
addCurve(int),
removeCurve,
clearCurves,
getNCurvespublic void addCurve(int iCurve)
getCurve,
addCurve(),
removeCurve,
clearCurves,
getNCurvespublic void clearCurves()
getCurve,
addCurve(),
addCurve(int),
removeCurve,
getNCurvespublic static java.lang.String formatAsHovertext(java.lang.String plainTextLabel)
When the string returned from this method is used as an argument to setHovertextTemplate, the hovertext that is generated is similar in format (light yellow background, black 1px border) to what is produced via the setTitle method (standard browser element hovertext).
In detail, this method creates the returned string via the line:
result = "<html><div style='background-color:#FFFFF0; border-color:black; border-style:solid; border-width:1px; padding:2px'>"
+ plainTextLabel + "</div>";
This method is provided mainly to simplify transitioning from the old hover feedback system to the new one introduced in v2.4.
It is expected that many pre v2.4 GChart applications will find that simply wrapping a formatAsHovertext call around existing hovertext templates will provide acceptable (though somewhat different) hover feedback for existing charts:
getCurve().getSymbol().setHovertextTemplate(
GChart.formatAsHovertext("(x,y) = (${x}, ${y})"));
Note that GChart v2.4 automatically includes such a wrapping formatAsHovertext call on all default hovertext templates.
See the setHoverAnnotationSymbolType method for a code snippet that emulates not
just the formatting, but also the at-the-mouse positioning behaviour, of
setTitle-based hovertext.
plainTextLabel - the plain text label that is to be HTML-wrapped to make it look
like setTitle-based hovertext.setHovertextTemplate,
setAnnotationText,
setHoverAnnotationSymbolTypepublic java.lang.String getBackgroundColor()
setBackgroundColorpublic java.lang.String getBorderColor()
setBorderColorpublic java.lang.String getBorderWidth()
setBorderWidthpublic java.lang.String getBorderStyle()
setBorderStylepublic com.google.gwt.user.client.ui.Widget getChartFootnotes()
setChartFootnotes(Widget),
setChartFootnotes(String),
getChartTitlepublic boolean getChartFootnotesLeftJustified()
setChartFootnotesLeftJustified,
setChartFootnotes(String),
setChartTitlepublic int getChartFootnotesThickness()
The width of this region always equals the width of the entire GChart (including legend and axis labels).
Your footnotes widget is always vertically centered in this region.
Your footnotes widget will either be horizontally centered in this region, or left justified in it, depending on the property defined by the setChartFootnotesLeftJustified method.
This method always returns 0 if the footnotes widget is null (the default); the rectangular footnotes region is entirely eliminated in that case.
setChartFootnotesThickness,
setChartFootnotesLeftJustifiedpublic com.google.gwt.user.client.ui.Widget getChartTitle()
setChartTitle(Widget),
setChartTitle(String)public int getChartTitleThickness()
This method always returns 0 if the title widget is null (the default); the rectangular title region is entirely eliminated in that case.
Your title widget is always centered vertically and horizontally within this rectangular region.
setChartTitleThicknesspublic boolean getClipToDecoratedChart()
setClipToDecoratedChartpublic boolean getClipToPlotArea()
setClipToPlotArea
public GChart.Curve.Point getClosestBrushTouchingPoint(int xPlotArea,
int yPlotArea)
This method only works if the chart rendering is up-to-date (if isUpdateNeeded returns false). Otherwise, null is returned.
GChart's hit testing method works best if a chart's points are approximately evenly distributed across the plot area's x or y axis, across a small number of curves. In particular, charts that have many points bunched up into a small part of the plot area, or that have many points completely outside of the plot area, or that place each point into a separate curve, could experience significantly worse that usual hit testing performance. Though such cases are expected to be rare, in the worst case, GChart could be reduced to a simple linear search across all the chart's points during hit testing.
xPlotArea - x-coordinate of trial mouse position, in GChart's plot area pixel
coordinates.yPlotArea - y-coordinate of trial mouse position, in GChart's plot area pixel
coordinates.
getMouseCoordinate,
modelToPlotAreaPixel,
isUpdateNeeded,
touchpublic GChart.Curve getCurve()
This method, when used in conjunction with no-arg addCurve, method, makes code blocks that create and define the properties of a chart's curves more readable/editable. For example:
addCurve(); // add 1st curve getCurve().setYAxis(Y2_AXIS); // first setting for 1st curve //... other settings for first curve addCurve(); // add 2nd curve getCurve().setYAxis(Y_AXIS); // first setting for 2nd curve // ... other settings for 2nd curve
Note that using the no-arg methods in this way allows you to copy entire groups of curve properties, unchanged, between such curve related blocks.
getCurve(int),
getNCurves,
addCurve()public GChart.Curve getCurve(int iCurve)
iCurve - index of the curve to be retrieved.
getCurve(),
addCurve(),
addCurve(int),
removeCurve,
clearCurves,
getNCurvespublic int getCurveIndex(GChart.Curve curve)
Returns GChart.NAI if the specified curve is not found on this GChart's curve list.
curve - whose list position is to be retrieved
getCurve(),
getCurve(int),
addCurve(),
addCurve(int),
removeCurve,
clearCurves,
getNCurvespublic java.lang.String getFontFamily()
setFontFamilypublic java.lang.String getGridColor()
setGridColorpublic java.lang.String getLegendBackgroundColor()
setLegendBackgroundColorpublic java.lang.String getLegendBorderColor()
setLegendBordergroundColor,
TRANSPARENT_BORDER_COLORpublic int getLegendBorderWidth()
setLegendBorderWidthpublic java.lang.String getLegendBorderStyle()
setLegendBorderStylepublic java.lang.String getLegendFontColor()
setLegendFontColorpublic int getLegendFontSize()
setLegendFontSizepublic java.lang.String getLegendFontFamily()
setLegendFontFamilypublic java.lang.String getLegendFontStyle()
setLegendFontStylepublic java.lang.String getLegendFontWeight()
setLegendFontWeightpublic int getLegendThickness()
The region extends vertically in parallel with the right edge of the plot area. The legend is always centered vertically and horizontally within this rectangular region.
This method always returns 0 if the legend is not visible; the rectangular legend region is entirely eliminated in that case.
setLegendThicknesspublic com.google.gwt.user.client.ui.Widget getLegend()
If null (the default) GChart will generate a legend widget internally.
setLegendpublic int getLegendXShift()
setLegendXShiftpublic double getInitialPieSliceOrientation()
setInitialPieSliceOrientationpublic int getLegendYShift()
setLegendYShiftpublic double getMaxCanvasPixels()
setMaxCanvasPixelspublic int getNCurves()
getCurve,
addCurve(),
addCurve(int),
removeCurve,
clearCurvespublic java.lang.String getPadding()
setPaddingpublic java.lang.String getPlotAreaBackgroundColor()
setPlotAreaBackgroundColorpublic java.lang.String getPlotAreaBorderColor()
setPlotAreaBorderColorpublic int getPlotAreaBorderWidth()
setPlotAreaBorderWidthpublic java.lang.String getPlotAreaBorderStyle()
setPlotAreaBorderStylepublic java.lang.String getPlotAreaImageURL()
setPlotAreaImageURL,
updatepublic boolean getOptimizeForMemory()
setOptimizeForMemorypublic double getRenderPaddingFactor()
setRenderPaddingFactorpublic boolean getShowOffChartPoints()
getClipToPlotAreapublic boolean getShowOffDecoratedChartGlyphs()
getClipToDecoratedChartpublic static java.lang.String getBlankImageURL()
setBlankImageURLpublic static java.lang.Object getCurrentCurveData()
Vector graphics widgets that implement GChartCanvasLite can use this method to retrieve auxiliary curve data that can then be used to control advanced features of the vector graphics ( GChartCanvasLite implementing) widget that GChart does not directly support. In other words, this method lets you access any custom curve specific data you may need to extend GChart's vector graphics capabilities in various ways.
For example, the GChart live demo uses this method to retrieve a special "Catmull-Rom tension parameter" from the curve's auxiliary data that it uses to adjust the amount of "curvyness" in its various connecting lines. By default, GChart only supports straight connecting lines so the live demo overrides the lineTo method in its GChartCanvasLite implementation so as to call the GWTCanvas method's cubicCurveTo to produce curvy connecting lines with the specified amount of "tension".
As you've probably gathered by now, this kind of thing is not for the faint of heart, and relies on hidden connections with aspects of GChart's internal implementation that could break your code in future GChart releases. On the other hand, there are a myriad of vector graphics library features GChart does not support (curvy lines, gradients, image-based area filling, etc.) and this "backdoor" approach is flexible enough that, if you work a bit, you may be able to exploit many of these advanced features in your charts.
If you implement such a rendering extension that would be helpful to others, please share it on the GChart issue tracker. As we learn more about how people exploit this backdoor, we can probably improve it, make it more reliable, and/or incorporate new vector graphics capabilities directly into GChart.
Tip: This method does not return a reference to the curve itself, because GChart's rendering code assumes that curve specifications proper do not change during rendering. If really you need to get at the curve itself, store a reference to it within your custom data object.
GChartCanvasLite,
setCanvasFactory,
setCurveDatapublic HoverParameterInterpreter getHoverParameterInterpreter()
setHoverParameterInterpreterpublic boolean getHoverTouchingEnabled()
setHoverTouchingEnabledpublic GChart.Axis getXAxis()
getYAxis,
getY2Axispublic int getXChartSize()
setXChartSizepublic int getXChartSizeDecorated()
The returned size does not include the border or padding around the chart as a whole.
You cannot directly set the decorated x chart size. Instead, you must set the width of the plot area, and the thicknesses of certain of the decoration-holding regions (using methods linked to below) that, summed together, define the total width of the chart.
setXChartSize,
getYChartSizeDecorated,
setAxisLabelThickness,
setTickLabelThickness,
setTickLength,
setTickLocation,
setTickLabelPadding,
setLegendThicknesspublic GChart.Axis getY2Axis()
getYAxis,
getXAxispublic GChart.Axis getYAxis()
getXAxis,
getY2Axispublic int getYChartSize()
setYChartSizepublic int getYChartSizeDecorated()
The returned size does not include the border or padding around the chart as a whole.
You cannot directly set the decorated y chart size. Instead, you must set sizes and thicknesses of the plot area and certain of the decoration-holding regions (using the methods linked-to below) that, when summed together, define the height of the decorated chart.
setYChartSize,
getXChartSizeDecorated,
setAxisLabelThickness,
setTickLabelThickness,
setTickLength,
setTickLocation,
setTickLabelPadding,
setChartTitleThickness,
setChartFootnotesThicknesspublic boolean hasY2Axis()
Only charts that have at least one curve on the right y axis will have a y2-axis.
Curve.setYAxispublic boolean hasYAxis()
Only charts that have at least one curve on the left y axis will have a y-axis.
Curve.setYAxispublic boolean isLegendVisible()
setLegendVisiblepublic boolean isUpdateNeeded()
Note: Whenever this method returns true, GChart "freezes" hover feedback, and can no longer actively track the currently "touched" point. This is because GChart, to simplify its bookkeeping, assumes in-browser (DOM) rendering and current chart specs are in synch when determining the point selection consequences of mouse events over the chart.
update,
getTouchedPointpublic void removeCurve(int iCurve)
iCurve - index of the curve to be removedremoveCurve(Curve),
getCurve,
addCurve(),
addCurve(int),
clearCurves,
getNCurvespublic void removeCurve(GChart.Curve curve)
If the given curve is null or is not a curve on this GChart, an exception is thrown.
curve - the curve to be removed.removeCurve(int)public void setBackgroundColor(java.lang.String cssColor)
The default background color is USE_CSS.
For more information on standard CSS color specifications see the
discussion in Symbol.setBackgroundColor.
cssColor - the chart's background color, in a standard CSS color string
format.USE_CSSpublic static void setBlankImageURL(java.lang.String blankImageURL)
When GWT compiles an application that imports the GChart library, it automatically adds an appropriate blank image, gchart.gif, to the module base directory (this is the directory into which GWT also copies your compiled Javascript, all the files in your public directory, etc.).
By default, GChart uses the following blank image URL:
GWT.getModuleBaseURL() + "gchart.gif"
Earlier versions used "gchart.gif" as this default url. This GWT forum post by Dean S. Jones identified the need to add the GWT.getModuleBaseURL() prefix.
Note that this default adds a potentially very long URL to every img element added by GChart to render your chart, which can (in theory) more than double the memory required to represent your chart in the browser, because the absolute URLs can be of undetermined length. In practice, browser memory usage increases of 10% have been observed with the on-line demo GChart and a typicial, 60-odd character absolute URL.
You have several alternatives to the above default that can often reduce the length of the URL and thus save browser memory:
Special note to anyone reading this who designed HTML's image tag: If you had provided a src=none option, this method would not have to exist.
Tip: If you already have an appropriate blank gif on your site that is accessible from the host page via a reasonably short URL there is no need to copy gchart.gif. You can just pass that URL to this method.
Note: Though GChart uses this blank image by default, you can use the setImageURL method to specify a non-blank image for use in rendering a specific curve.
blankImageURL - a URL that points to a 1 x 1 pixel transparent image that GChart
needs to render your charts without adding a spurious
"missing image" icon.getBlankImageURL,
DEFAULT_BLANK_IMAGE_URL,
setImageURLpublic void setBorderColor(java.lang.String cssColor)
The default border color is USE_CSS.
Tip: No border will appear if either borderStyle is none, borderWidth is 0px or borderColor is transparent. Since these will often be the "CSS inherited" values, generally, it's best to set all three properties whenever you set any one of them.
For more information on standard CSS color specifications see the
discussion in Symbol.setBackgroundColor.
cssColor - the color of the chart's border, in a standard CSS color string
format.setBorderWidth,
setBorderStyle,
getBorderColor,
USE_CSSpublic void setBorderStyle(java.lang.String borderStyle)
The default border style is USE_CSS.
Tip: No border will appear if either borderStyle is none, borderWidth is 0px or borderColor is transparent. Since these will often be the "CSS inherited" values, generally, it's best to set all three properties whenever you set any one of them.
borderStyle - a CSS border style such as "solid", "dotted", "dashed", etc.getBorderStyle,
setBackgroundColor,
setBorderColor,
setBorderWidth,
USE_CSSpublic void setBorderWidth(java.lang.String cssWidth)
The default border width is USE_CSS.
Tip: No border will appear if either borderStyle is none, borderWidth is 0px or borderColor is transparent. Since these will often be the "CSS inherited" values, generally, it's best to set all three properties whenever you set any one of them.
cssWidth - width of the border around the chart as a whole, expressed as a
CSS border-width specification string, such as "1px".getBorderWidth,
setBorderStyle,
setBorderColor,
USE_CSS
public void setCanvasExpansionFactors(double widthExpansionFactor,
double heightExpansionFactor)
If you plug in an external vector graphics library via setCanvasFactory, GChart creates a vector graphics "canvas" for each curve that is just big enough to contain the points on that curve. These "shrink-wrapped" canvas rectangles save memory. But, if you use Bezier curves, your curves can easily extend outside of these rectangles. So, this method lets you "pad" these canvas rectangles with extra space, thus preventing such "overshooting" curves from being improperly clipped off.
To handle every possible Bezier overshoot contingency, these canvas expansion factors would have to be huge. But, in the oil price simulation of the live demo, even with its "100% curvy" option, a factor of 0.3 on the y axis and 0.0 on the x axis (a 30% memory hit for this chart) works well. 0.1 on y even works OK, if you don't mind truncatiing the wildest overshooting curves.
widthExpansionFactor - the fraction that the width of the canvas rectangle will be
expanded. The default is 0 (no width expansion).heightExpansionFactor - the fraction that the height of the canvas rectangle will be
expanded. The default is 0 (no height expansion).setCanvasFactorypublic void setChartFootnotes(java.lang.String html)
html - HTML text used to define the chart's title.setChartFootnotes(Widget)public void setChartFootnotes(com.google.gwt.user.client.ui.Widget chartFootnotes)
The widget will vertically centered within a band just below the x axis label that stretches along the entire bottom edge of the chart, and whose height is defined by setChartFootnotesThickness.
The widget will either be left justified, or horizontally centered, within this band depending on the property defined by setChartFootnotesLeftJustified
chartFootnotes - widget representing the chart's footnotessetChartFootnotes(String),
setChartFootnotesThickness,
getChartFootnotes,
setChartFootnotesLeftJustifiedpublic void setChartFootnotesLeftJustified(boolean footnotesLeftJustified)
Note that a chart's footnotes are always vertically centered within the band at the bottom of the chart reserved for chart footnotes. Use the setChartFootnotesThickness method to set the height of this band.
footnotesLeftJustified - true to position chart footnotes flush against the left edge of
the chart, false (the default) to center them horizontally across
the chart's bottom edge.setChartFootnotes(String),
getChartFootnotes,
setChartFootnotesThickness(int)public void setChartFootnotesThickness(int thickness)
The width of this region always equals the width of the entire GChart (including legend and axis labels).
Your footnotes widget is always vertically centered in this region.
Your footnotes widget will either be horizontally centered in this region, or left justified in it, depending on the property defined by the setChartFootnotesLeftJustified method.
This setting has no impact on chart layout if the footnotes widget is null (the default); the rectangular footnotes region is entirely eliminated, and in effect has a 0 thickness, in that case.
If you set the footnotes thickness to GChart.NAI (the default) GChart will use a thickness based on the estimated number of ( <br> or <li> delimited) lines.
thickness - the thickness (height) of the rectangle that contains the
footnotes, in pixels, or GChart.NAI to use the default
thickness.getChartFootnotesThickness,
setChartFootnotesLeftJustified,
GChart.NAI,
DEFAULT_FOOTNOTES_THICKNESS
public void setChartSize(int xChartSize,
int yChartSize)
xChartSize - number of x-pixels in the curve display area of the chartyChartSize - number of y-pixels in the curve display area of the chartsetXChartSize,
setYChartSizepublic void setChartTitle(java.lang.String html)
html - HTML text used to define the chart's title.setChartTitle(Widget)public void setChartTitle(com.google.gwt.user.client.ui.Widget chartTitle)
chartTitle - the widget to be used as this chart's title.setChartTitle(String),
setChartTitleThickness,
getChartTitlepublic void setChartTitleThickness(int thickness)
Your title widget is always centered vertically and horizontally within this rectangular region.
This setting has no impact on chart layout if the title widget is null, since the title-holding region is entirely eliminated in that case. If you set the title thickness to GChart.NAI (the default) GChart will use a thickness that is based on the the number of <br> or <li> delimited HTML lines if the title Widget implements HasHTML.
thickness - the thickness (height) of the rectangle that contains the title,
in pixels, or GChart.NAI to use the default thickness.getChartTitleThickness,
GChart.NAI,
DEFAULT_TITLE_THICKNESSpublic void setClipToDecoratedChart(boolean clipToDecoratedChart)
The decorated chart includes not just the plot area, but space allocated for titles, footnotes, legend key, axis labels, tick marks, etc. The size of this decorated chart can be obtained via the getXChartSizeDecorated and getYChartSizeDecorated methods.
Note that, in non-IE browsers, drawing a curve via GWTCanvas that falls outside the bounds of the decorated chart could occlude mouse events over elements on the enclosing page that fall within the smallest bounding rectangle that contains the canvas-rendered curve. HTML rendering (IE's element-based VML used by GWTCanvas is essentially HTML-like in this respect) only creates such occlusions at the positions where the curve is actually rendered.
clipToDecoratedChart - use true to clip off-the-decorated-chart symbols,
annotations, etc. or false (the default) to allow such
chart elements to be drawn outside of the rectangular region
allocated for the chart.getClipToDecoratedChart,
GChart.setClipToPlotArea,
Curve.setClipToPlotArea,
getXChartSizeDecorated,
getYChartSizeDecorated,
setCanvasFactorypublic void setClipToPlotArea(boolean clipToPlotArea)
Note: This clipping does not apply to the hover selection feedback. In particular, points that fall outside the plot area, though not visible, will still display their selection feedback and pop-up hover annotations when the user mouses over them.
clipToPlotArea - false (the default) to display off-the-plot-area
graphics, true to clip them off.getClipToPlotArea,
setClipToDecoratedChart,
Curve.setClipToPlotAreapublic static void setDefaultSymbolBorderColors(java.lang.String[] defaultBorderColors)
GChart uses the first color in this array as the default border color of the first curve added (via addCurve), the second color for the second curve added, and so on. If more curves are added than the number of elements in the default border colors array, the sequence is repeated.
Note that each curve/symbol's default color is "locked in" at the point when that curve/symbol is first added, based on the total number of curves at that time.
Because, by default, GChart uses a transparent symbol background color, the default border color will usually, in effect, define the default color of each curve. The default border color also defines the default color of point-to-point connecting lines in a line chart.
If not explicitly specified via this method, GChart uses GChart.DEFAULT_SYMBOL_BORDER_COLORS by default. However, most people find the color sequence used by OpenOffice's Charts more aesthetically pleasing. The World's Simplest Line Chart Editor example chart contains a line of code that makes GChart use the OpenOffice defaults.
This feature was added in response to an email from Joe Cole and this post by Sanjiv Jivan. They both pointed out the importance of changing GChart's default colors.
defaultBorderColors - array of CSS color strings whose successive elements define the
initial symbol border colors for curves in the order that they are
added.DEFAULT_SYMBOL_BORDER_COLORS,
TRANSPARENT_BORDER_COLOR,
setBackgroundColor,
setBorderColor,
addCurvepublic void setFontFamily(java.lang.String fontFamily)
This chart-specific default font family setting will be overridden if a more specific method of setting the font family has been employed.
The default overall font family is DEFAULT_FONT_FAMILY.
setTickLabelFontFamily,
setAnnotationFontFamily,
setLegendFontFamily,
DEFAULT_FONT_FAMILYpublic void setGridColor(java.lang.String cssColor)
For more information on standard CSS color specifications see the
discussion in Symbol.setBackgroundColor.
cssColor - the color, in CSS standard color format, to be used for all
gridlines, axes, and tick marks.getGridColor,
DEFAULT_GRID_COLORpublic void setHoverParameterInterpreter(HoverParameterInterpreter hpi)
Hovertext template strings can include ${... } bracketed references to built-in parameters such as ${x} and ${y} that get get replaced with appropriate string representations of the x or y values of the hovered-over point in displayed hovertext. You can add new, custom, named parameters, and/or redefine the meaning of built-in parameters, by passing a hover parameter interpreter to this method.
For sample code that shows you how to define a hover parameter interpreter, see HoverParameterInterpreter.
hpi - the hover parameter interpreter to use with all hovertext
templates on this GChart (this interpreter is responsible for
replacing ${...} bracketed embedded parameter
names in the hover text template with appropriate HTML snippets
representing the value of that parameter at the hovered-over
point).HoverParameterInterpreter,
setHovertextTemplatepublic void setHoverTouchingEnabled(boolean hoverTouchingEnabled)
With the default of true, points are auto-selected as the user "touches" them with the mouse-attached "brush"--no clicking is required.
When hover touching is disabled, a GChart can be used in a manner analogous to a single-selection (sorry there's no multi-selection capability) listbox, with its click-selectable points playing the role of the selectable list items. Specifically, disabling hover touching lets you move the mouse freely without any danger of changing the selected point--the point even remains selected if the mouse moves entirely off the chart. This is helpful when your application follows the common pattern of "select the thing you want to operate on, then issue a command that operates on that thing". This option is also helpful if you use very compute-intensive hover widgets, or if you simply prefer explictly-clicked-open/closed pop-up annotations.
How to Stop Leaky Clicks: In IE7 and the hosted mode browser, clicking ahead on a Button widget "leaks" clicks upwards to the enclosing parent, even if you call event.cancelBubble(true). Such "leaky clicks" can inappropriately change the selected point, when you really just wanted to operate on it. This does not happen in Firefox 2, 3, or Chrome, whose buttons properly "eat" the clicks--even when they come in fast. To workaround the problem, you can place the buttons into a hover widget (as shown in GChartExample21.java in the chart gallery). This works because GChart applies checks that ignore any mouse events that occur within the rectangular region associated with the opened hover widget.
For an example that uses setHoverTouchingEnabled(false) to allow the user to change the y-value of the selected point, see the Chart Gallery's GChartExample21.
hoverTouchingEnabled - true (the default) if you want users to be able to select
points simply by hovering over them with their mouse,
false if you want to require that they actually click on
points to select them.getHoverTouchingEnabled,
setBrushHeight,
touch,
update,
HoverUpdateablepublic void setInitialPieSliceOrientation(double orientation)
The default initial orientation is used as the first pie slice's first edge's orientation setting only if the symbol associated with that pie slice has the default, undefined, orientation setting of Double.NaN.
The default value of this setting is 0, which corresponds to due south (6 o'clock). The value specifies the fraction of a complete clockwise rotation, beginning at due south, required to reach the first edge of the pie slice.
orientation - the orientation to use for the first edge of the first pie slice
in this GChart, in cases in which that first pie slice's
orientation is undefined (Double.NaN).setPieSliceOrientationpublic void setLegendBackgroundColor(java.lang.String cssColor)
For more information on standard CSS color specifications see the
discussion in Symbol.setBackgroundColor.
cssColor - the legend's background color, in a standard CSS color string
format.getLegendBackgroundColor,
DEFAULT_LEGEND_BACKGROUND_COLORpublic void setLegendBorderColor(java.lang.String cssColor)
For more information on standard CSS color specifications see the
discussion in Symbol.setBackgroundColor.
cssColor - the color of the legend's border, in a standard CSS color string
format, of the special GChart keyword
TRANSPARENT_BORDER_COLOR for a transparent border.getLegendBorderColor,
DEFAULT_LEGEND_BORDER_COLOR,
TRANSPARENT_BORDER_COLORpublic void setLegendBorderWidth(int width)
width - the width of the legend's border, in pixelsgetLegendBorderWidth,
DEFAULT_LEGEND_BORDER_WIDTHpublic void setLegendBorderStyle(java.lang.String borderStyle)
borderStyle - a CSS border style such as "solid", "dotted", "dashed", etc.getLegendBorderStyle,
setLegendBackgroundColor,
setLegendBorderColor,
DEFAULT_LEGEND_BORDER_STYLEpublic void setLegendFontColor(java.lang.String cssColor)
For more information on standard CSS color specifications see the
discussion in Symbol.setBackgroundColor.
cssColor - color of the font used to display the labels in the legend.getLegendFontColor,
DEFAULT_FONT_COLORpublic void setLegendFontSize(int legendFontSize)
This size also governs the size of the symbol icon displayed in the legend.
Default is DEFAULT_LEGEND_FONTSIZE.
legendFontSize - the font size of legend textgetLegendFontSize,
DEFAULT_LEGEND_FONTSIZEpublic void setLegendFontFamily(java.lang.String cssFontFamily)
If null (the default) the legend will just use the font family specified via GChart.setFontFamily.
cssFontFamily - any valid CSS font-family, such as
"serif", "sans-serif", "monospace", "cursive",
* "fantasy" or "Arial, sans-serif".getLegendFontFamily,
DEFAULT_FONT_FAMILYpublic void setLegendFontStyle(java.lang.String cssStyle)
cssStyle - any valid CSS font-style, namely, normal, italic, oblique, or
inherit.getLegendFontStyle,
DEFAULT_FONT_STYLEpublic void setLegendFontWeight(java.lang.String cssWeight)
cssWeight - a CSS font-weight specification, such as bold, bolder, normal,
light, 100, 200, ... or 900.getLegendFontWeight,
DEFAULT_FONT_WEIGHTpublic void setLegendLocation(GChart.LegendLocation legendLocation)
The default LegendLocation is LegendLocation.OUTSIDE_RIGHT.
To shift the legend relative to these base locations, use setLegendXShift and setLegendYShift.
legendLocation - the postion of the legend on the chartsetLegendXShift,
setLegendYShift,
setLegendpublic void setLegend(com.google.gwt.user.client.ui.Widget legend)
Passing in null reverts to the default GChart-generated legend.
legend - - a Widget that will be placed at the location specified by
setLegendLocation, or null to let GChart create
the legend Widget.getLegend,
setLegendLocation,
setLegendXShift,
setLegendYShiftpublic void setLegendXShift(int xShift)
xShift - number of pixels to move legend along the x axis from it's
default, LegendLocation-defined, position.setLegendLocation,
setLegendYShiftpublic void setLegendYShift(int yShift)
yShift - number of pixels to move legend along the y axis from it's
default, LegendLocation-defined, position.setLegendLocation,
setLegendXShiftpublic void setLegendThickness(int legendThickness)
This setting has no impact on chart layout if the legend key is not visible, or if the legend key is placed inside the plot area of the chart, since the legend takes up no space on the left or right sides of the chart in such cases.
If the legend thickness is set to GChart.NAI (the default) GChart uses an heuristic to set the legend thickness based on the number of characters in each curve's legend label.
legendThickness - the thickness (width) of the rectangle that contains the legend
key, in pixels, or GChart.NAI to use a built-in heurstic
to determine the legend width.getLegendThickness,
setLegendLabel,
Y2Axis.setAxisLabelThicknesspublic void setLegendVisible(boolean isLegendVisible)
isLegendVisible - true to display the legend, false to hide it.isLegendVisible,
setLegendLabelpublic void setMaxCanvasPixels(double maxCanvasPixels)
If the number of pixels ever exceeds this amount, GChart will scale the offending canvas down uniformly in width and height, until it has around the specified number of pixels, and then move it as close to being centered on the plot area as is consistent with remaining within the original, unshrunken, clipping rectangle. This strategy means that points furthest off the plot area could be dropped due to this max pixel limit.
Because GChart allows you to draw outside of the decorated chart, the size of the required canvas is not always known in advance. But the use of very large sized canvas widgets can lead to serious performance problems (including large memory use on some browsers, e.g. Firefox). This method provides a simple way for developers to avoid such problems without having to explicitly eliminate "far off the chart" data points from their charts.
maxCanvasPixels - the maximum number of pixels any single GChart canvas Widget
(GChartCanvasLite) will contain.DEFAULT_MAX_CANVAS_PIXELS,
getMaxCanvasPixelspublic void setOptimizeForMemory(boolean optimizeForMemory)
If optimizeForMemory is set to true, GChart will (at the very next update() call) free up any Image or Grid elements that are no longer required to render the current chart. Should a chart's size grow back to a former size, the subsequent update would be slower, though.
Charts that use exactly the same number of Image and Grid elements for each update (for example a bar chart where the number of bars is fixed) will see no impact on either memory use or update speeds by setting this parameter. Charts that have a highly variable number of Image or Grid elements (for example, a chart whose number of points varies randomly between 5 and 500) may see a very large impact on speed (false is faster) or memory (true is more compact).
The setting of this parameter never has any impact on the speed or memory used on the very first chart update.
In one test using the future oil price simulation chart of GChart's live demo (which has only small changes in the number of elements required to render the chart between updates) setting this parameter to true made the updates, on average, around 10% slower, but also reduced the memory footprint by around 2%.
optimizeForMemory - true to optimize updates to use less memory,
false (the default) to optimize them to use less time.updatepublic void setPadding(java.lang.String cssPadding)
The default padding is USE_CSS.
cssPadding - the width of the padding, as a CSS padding specification string
(e.g. use "1px" to introduce a 1 pixel padding just between the
chart' border and the chart itself)getPadding,
setBorderWidth,
setBorderStyle,
setBorderColor,
USE_CSSpublic void setPlotAreaBackgroundColor(java.lang.String cssColor)
For more information on standard CSS color specifications see the
discussion in Symbol.setBackgroundColor.
cssColor - CSS color string defining the plot area's background colorgetPlotAreaBackgroundColorpublic void setPlotAreaBorderColor(java.lang.String cssColor)
For more information on standard CSS color specifications see the
discussion in Symbol.setBackgroundColor.
cssColor - CSS color string defining the color of the plot area's bordergetPlotAreaBorderColorpublic void setPlotAreaBorderWidth(int width)
width - the width, in pixels, of the border around the plot areagetPlotAreaBorderWidthpublic void setPlotAreaBorderStyle(java.lang.String borderStyle)
borderStyle - a CSS border style such as "solid", "dotted", "dashed", etc.getPlotAreaBorderStyle,
setPlotAreaBackgroundColor,
setPlotAreaBorderColorpublic void setPlotAreaImageURL(java.lang.String imageURL)
Note that by default, or if this URL is set to null, GChart will use the URL returned by getBlankImageURL.
Ideas/tips for using the plot area background URL:
imageURL - URL of the image used as the background of the plot area.getPlotAreaImageURL,
setBlankImageURL,
setImageURLpublic void setRenderPaddingFactor(double renderPaddingFactor)
By default, this factor is 0.0 and GChart is free to skip the rendering any parts of the chart that would have been clipped off anyway. However, special applications, such as panning, may find it advantageous to fully render areas adjacent to the clipping window, so that these pre-rendered areas can then be quickly shifted into view via the setXShift and setYShift methods.
The width and height of the clipping window (typically the plot area) are expanded by the specified fraction along each edge. For example, a render padding factor of 1.0 expands the rendered height by a factor of 300% (100% extra above, and 100% extra below) and the width by the same factor (100% extra to the left, and 100% extra to the right).
renderPaddingFactor - the fractional amount to expand to the rendering window around the
perimeter of the clipping window.setXShift,
setYShift,
getRenderPaddingFactorpublic void setShowOffChartPoints(boolean showOffChartPoints)
As of GChart 2.5, the clip-to-plot-area algorithm no longer drops the entire symbol if it's x,y coordinates are outside of the plot area; instead, it clips them off in the traditional "overflow: hidden" manner. Though unlikely you would need to, there is no easy way to recreate the previous behavior.
This change was made so that both rectangular HTML and continuous, canvas-rendered chart elements would be clipped in a consistent and sensible way.
setClipToPlotAreapublic void setShowOffDecoratedChartGlyphs(boolean showOffDecoratedChartGlyphs)
setClipToDecoratedChartpublic GChart.Curve getTouchedCurve()
Convenience method equivalent to (when the touched point is not null) getTouchedPoint().getParent(). See getTouchedPoint for full details.
See the setBrushHeight method for the rules GChart uses to determine the currently touched point.
getTouchedPoint,
setBrushHeight,
setHoverSelectionSymbolTypepublic GChart.Curve.Point getTouchedPoint()
Fine-print: If the chart clicked on needs an update, this method returns the touched point as of the last time the chart's in-browser (DOM) display was up-to-date. If you don't assure that your chart's DOM display is up-to-date via other means (e.g. updating right after you change its specifications) a quick check with the isUpdateNeeded method and a subsequent update before accessing the touched point can be a good strategy.
See the setBrushHeight method for the rules GChart uses to determine the currently touched point.
Warning: The currently touched point, on FF2 (but not in IE7) can be changed (or set to null) by invoking Window.alert. Though I originally expected that such a modal alert box would "eat" all mouse events (and it does just that in IE7) in FF2 (and possibly other browsers) some mouse events on the alert box are also passed on up to the GChart. It's best for applications that need to "lock on" to the initially touched point to grab a reference to the touched point before performing any activity that allows the user to interact with the browser in ways that could possibly generate GChart-visible mouse events.
getTouchedCurve,
touch,
setBrushHeight,
setHoverSelectionSymbolType,
isUpdateNeeded,
update,
getMouseCoordinate,
clientToModel,
modelToClient,
pixelToModel,
modelToPixelpublic void setXChartSize(int xChartSize)
Note: Most modern display devices use "square" pixels, that is, pixels whose width and height are the same. GChart tacitly assumes square pixels in many of its default settings.
xChartSize - the number of x-pixels in the chart region used for curve display.getXChartSize,
getXChartSizeDecorated,
setYChartSizepublic void setYChartSize(int yChartSize)
Note: Most modern display devices use "square" pixels, that is, pixels whose width and height are the same. GChart tacitly assumes square pixels in many of its default settings.
yChartSize - the number of y-pixels in the chart region used for curve display.getYChartSize,
getYChartSizeDecorated,
setXChartSizepublic void touch(GChart.Curve.Point pointToTouch)
Note that, as with all chart specification changes, you must invoke update before the point selection and other changes associated with this method will appear on the chart.
Tip: The touched point can sometimes be used in lieu of a point selection capability (which GChart lacks). For example, a dialog box that allowed users to choose data points by their names could "touch" the point associated with a user-selected name in order to highlight it on the chart.
pointToTouch - this method will perform appropriate
operations (as described above) in order to simulate the user
"touching" this point with their mouse.getTouchedPoint,
getTouchedCurve,
hoverUpdate,
hoverCleanup,
setHoverWidget,
setHoverLocation,
setHoverSelectionBorderColor,
getMouseCoordinate,
clientToModel,
modelToClient,
pixelToModel,
modelToPixelpublic void update(GChart.TouchedPointUpdateOption option)
Before any of the chart specifications of the other methods of this class will actually be visible on the chart, you must call this method.
Typically, for efficiency, you would call this method only after you had made all of the desired chart specifications via the other methods.
By default, updates are optimized for speed, and this can end up wasting (usually not too much, though there are exceptions) memory. To optimize for memory instead, use the setOptimizeForMemory method.
For a discussion of Client-side GChart update times and how minimize them, see Tips for Making Client-side GChart Updates Faster.
Note Hover feedback is disabled whenever the currently rendered chart does not match current chart specs, that is, whenever isUpdateNeeded returns true. Thus, to assure that hover feedback remains operational once your code returns control to the browser, be sure to call update() after making a series of changes to your chart's properties.
Understanding how update impacts visibility and size:
Due to an implementation-related limitation, visibility: hidden won't hide a GChart (update commandeers the visibility attribute). Instead use display: none or, equivalently:myGChart.setVisible(false);If you need to avoid display: none (it can change page layout), you can also hide a GChart via lines such as:DOM.setStyleAttribute(myGChart.getElement(), "overflow", "hidden"); myGChart.setPixelSize(0, 0);This later approach gives you the option of leaving the top corner of the GChart visible, etc. Note that, with the next update, GChart will overwrite your size (based on the GChart properties that define the size of the the chart, such as setChartSize and set*Thickness) and your overflow:hidden (based on setClipToDecoratedChart) specifications. To preserve them (or in other special cases) you may need to apply such settings to an enclosing parent element.
option - determines how the touched (or "hovered over") point changes as a
result of this update. See TouchedPointUpdateOption for
the available choices.TouchedPointUpdateOption,
setOptimizeForMemory,
isUpdateNeededpublic void update()
A convenience method equivalent to:
if (getHoverTouchingEnabled()) update(TouchedPointUpdateOption.TOUCHED_POINT_UPDATED); else update(TouchedPointUpdateOption.TOUCHED_POINT_LOCKED);
update(TouchedPointUpdateOption),
setHoverTouchingEnabled
|
For downloads, demos, and more
visit the Client-side GChart Home Page |
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||