package com.googlecode.gchart.gcharttestapp.client; import com.google.gwt.event.dom.client.ClickEvent; import com.google.gwt.event.dom.client.ClickHandler; import com.googlecode.gchart.client.GChart; /** * * This chart allows the user to delete points by clicking * on them, and to add points at the mouse location, by * clicking on empty space.
* * New points are inserted at the current curve's insertion * index which begins at the end of the curve and is * maintained at the position of the last deleted, or just * after the last inserted, point.
* * Initially, six 1-point "starter curves" are placed along * the y axis. By deleting and immediately recreating * those points, the user can switch to adding points * to a different curve. The screen shot shows what the * chart looks like after the user has extended the * bottom two curves across the chart, with the other * four curves in their initial, "starter curve" * configuration. * */ public class GChartExample22a extends GChart implements ClickHandler { final int MAX_CURVES = 6; int[] insertionPoint = new int[MAX_CURVES]; int insertionCurve = 0; public void onClick(ClickEvent event) { if (null == getTouchedPoint()) { // add point at mouse position getCurve(insertionCurve).addPoint( insertionPoint[insertionCurve]++, getXAxis().getMouseCoordinate(), getYAxis().getMouseCoordinate()); } else { // delete the clicked on point insertionCurve = getCurveIndex(getTouchedCurve()); insertionPoint[insertionCurve] = getTouchedCurve().getPointIndex( getTouchedPoint()); getTouchedCurve().removePoint(getTouchedPoint()); } update(); } GChartExample22a() { setChartSize(300, 300); setBorderStyle("none"); /* * Switch to OpenOffice color sequence (it looks * better). Though the legal situation for colors * is a bit murky, since it is part of * LGPL * licensed OpenOffice, this color sequence, if * used for the specific purpose of a default chart * color sequence, and hence this * example code line, is likely itself also copy * protected under the LGPL * Use only as directed. *
* * Note that the GChart library itself (gchart.jar) * contains only Apache 2.0 licensed code. * * * This page provides a nice picture of the OpenOffice color * sequence, and details on the voting process used * to select it.
* */ GChart.setDefaultSymbolBorderColors(new String[] { "#004586", "#ff420e", "#ffd320", "#579d1c", "#7e0021", "#83caff", "#314004", "#aecf00", "#4b1f6f", "#ff950e", "#c5000b", "#0084d1"}); setChartTitle("