我在與創建GWT MotionChart問題。我想圖表看起來像以下: http://code.google.com/apis/chart/interactive/docs/gallery/motionchart.html#notesGWT - motionchart/Date對象
以下是我的代碼:
package component.client.widgets;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.Locale;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.visualization.client.AbstractDataTable;
import com.google.gwt.visualization.client.DataTable;
import com.google.gwt.visualization.client.VisualizationUtils;
import com.google.gwt.visualization.client.visualizations.LineChart;
import com.google.gwt.visualization.client.visualizations.MotionChart;
import com.google.gwt.visualization.client.visualizations.MotionChart.Options;
import com.google.gwt.visualization.client.AbstractDataTable.ColumnType;
import com.google.gwt.core.client.GWT;
import com.google.gwt.i18n.client.DateTimeFormat;
import component.client.SQLRunner;
import component.client.SQLRunnerAsync;
public class DashboardWidget
{
private HorizontalPanel containerPanel=null;
private DataTable data=null;
public DashboardWidget()
{
containerPanel = new HorizontalPanel();
}
public HorizontalPanel getContainerPanel()
{
SQLRunnerAsync service = (SQLRunnerAsync) GWT.create(SQLRunner.class);
AsyncCallback<ArrayList<String[]>> callback = new AsyncCallback<ArrayList<String[]>>()
{
@Override
public void onFailure(Throwable caught)
{
}
@Override
public void onSuccess(final ArrayList<String[]> result)
{
Runnable onLoadCallback = new Runnable()
{
public void run()
{
String date1="1988,0,1";
String date2="1988,0,1";
String date3="1988,0,1";
String date4="1988,1,1";
String date5="1988,1,1";
String date6="1988,1,1";
DateTimeFormat fmt = DateTimeFormat.getFormat("yyyy,M,d");
Date d1 = fmt.parse(date1);
Date d2 = fmt.parse(date2);
Date d3 = fmt.parse(date3);
Date d4 = fmt.parse(date4);
Date d5 = fmt.parse(date5);
Date d6 = fmt.parse(date6);
data.addRows(6);
data.addColumn(ColumnType.STRING,"Fruit");
data.addColumn(ColumnType.DATE, "Date");
data.addColumn(ColumnType.NUMBER, "Sales");
data.addColumn(ColumnType.NUMBER, "Expenses");
data.addColumn(ColumnType.STRING, "Location");
data.setValue(0, 0, "Apples");
data.setValue(0, 1, d1);
data.setValue(0, 2, 1000);
data.setValue(0, 3, 300);
data.setValue(0, 4, "East");
data.setValue(1, 0, "Oranges");
data.setValue(1, 1, d2);
data.setValue(1, 2, 950);
data.setValue(1, 3, 200);
data.setValue(1, 4, "West");
data.setValue(2, 0, "Bananas");
data.setValue(2, 1, d3);
data.setValue(2, 2, 300);
data.setValue(2, 3, 250);
data.setValue(2, 4, "West");
data.setValue(3, 0, "Apples");
data.setValue(3, 1, d4);
data.setValue(3, 2, 1200);
data.setValue(3, 3, 400);
data.setValue(3, 4, "East");
data.setValue(4, 0, "Oranges");
data.setValue(4, 1, d5);
data.setValue(4, 2, 900);
data.setValue(4, 3, 150);
data.setValue(4, 4, "West");
data.setValue(5, 0, "Bananas");
data.setValue(5, 1, d6);
data.setValue(5, 2, 788);
data.setValue(5, 3, 617);
data.setValue(5, 4, "West");
Options options = Options.create();
options.setWidth(1000);
options.setHeight(1000);
MotionChart chart = new MotionChart(data, options);
containerPanel.add(chart);
}
};
VisualizationUtils.loadVisualizationApi(onLoadCallback, MotionChart.PACKAGE);
}
};
service.getSomeStuffFromDB("","","","", callback);
return containerPanel;
}
}
但是我得到錯誤:
java.lang.IllegalArgumentException異常:1988,0,1 at com.google.gwt.i18n.client.DateTimeFormat.parse(DateTimeFormat.java:1579) at com.google.gwt.i18n.client.DateTimeFormat.parse(DateTimeFormat.java:1049) at component.client.widgets .DashboardWidget $ 1 $ 1.run(DashboardWidget.java:89) 在com.google.gwt.ajaxloader.client.ExceptionHelper.runProtected(ExceptionHelper.java:36) 在sun.reflect.NativeMethodAccessorImpl.invoke0(本機方法) 在sun.reflect.NativeMethodAccessorImpl.invoke(來源不明) 在sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at com.google.gwt.dev.shell.MethodAdaptor.invoke(MethodAdaptor.java:103) at com.google.gwt.dev.shell.MethodDispatch.invoke(MethodDispatch.java:71) 在com.google.gwt.dev.shell.OophmSessionHandler.invoke(OophmSessionHandler.java:167) 在com.google.gwt。 dev.shell.BrowserChannelServer.reactToMessages(BrowserChannelServer.java:281) 在com.google.gwt.dev.shell .BrowserChannelServer.processConnection(BrowserChannelServer.java:531) 在com.google.gwt.dev.shell.BrowserChannelServer.run(BrowserChannelServer.java:352) 在java.lang.Thread.run(未知來源)
我假設它與日期對象有關。有人能指出我做錯了什麼嗎?
非常感謝。
謝謝。那工作。 – sap