gpt4 book ai didi

java - 如何设置 Google 可视化动态图表的状态?

转载 作者:行者123 更新时间:2023-12-01 05:50:39 25 4
gpt4 key购买 nike

我正在使用 GWT 和 Google Chart Tools (aka Visualization) 1.1 Library Google API Libraries for GWT的.

我想显示动态图表并在 Javascript 中尽可能设置状态。

有人知道如何设置状态吗?

最佳答案

这里是 GWT 入门页面中稍微修改的 MotionChart,其中包含来自 Javascript 文档的数据。我没有测试过,所以我不确定代码是否有效。

public class SimpleViz implements EntryPoint {
public void onModuleLoad() {
// Create a callback to be called when the visualization API
// has been loaded.
Runnable onLoadCallback = new Runnable() {
public void run() {
Panel panel = RootPanel.get();

MotionChart chart = new MotionChart(createTable(), createOptions());

panel.add(chart);
}
};
VisualizationUtils.loadVisualizationApi(onLoadCallback, MotionChart.PACKAGE);
}

private Options createOptions() {
Options options = Options.create();
options.setWidth(600);
options.setHeight(300);
options.setTitle("My Motion Chart");

// Passing JSON state with escaped double quotes to options class.
options.setState("{\"orderedByY\":false,\"showTrails\":true,\"dimensions\":{\"iconDimensions\":[\"dim0\"]},\"yAxisOption\":\"3\",\"xZoomedIn\":false,\"time\":\"1988-04-16\",\"yZoomedIn\":false,\"xAxisOption\":\"2\",\"yZoomedDataMin\":150,\"yZoomedDataMax\":617,\"xZoomedDataMin\":300,\"uniColorForNonSelected\":false,\"xLambda\":1,\"playDuration\":15000,\"yLambda\":1,\"duration\":{\"timeUnit\":\"D\",\"multiplier\":1},\"iconType\":\"BUBBLE\",\"iconKeySettings\":[{\"trailStart\":\"1988\",\"key\":{\"dim0\":\"Apples\"}},{\"trailStart\":\"1988\",\"key\":{\"dim0\":\"Oranges\"}},{\"trailStart\":\"1988\",\"key\":{\"dim0\":\"Bananas\"}}],\"colorOption\":\"2\",\"xZoomedDataMax\":1200,\"nonSelectedAlpha\":0.4,\"orderedByX\":false,\"sizeOption\":\"_UNISIZE\"}");
return options;
}

private AbstractDataTable createTable() {
DataTable data = DataTable.create();
data.addColumn('string', 'Fruit');
data.addColumn('date', 'Date');
data.addColumn('number', 'Sales');
data.addColumn('number', 'Expenses');
data.addColumn('string', 'Location');
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.addRows(6);
data.setValue(0, 0, "Apples");
data.setValue(0, 1, new Date (1988,0,1));
data.setValue(0, 2, 1000);
data.setValue(0, 3, 300);
data.setValue(0, 4, "East");
data.setValue(1, 0, "Oranges");
data.setValue(1, 1, new Date (1988,0,1));
data.setValue(1, 2, 1150);
data.setValue(1, 3, 200);
data.setValue(1, 4, "West");
data.setValue(2, 0, "Bananas");
data.setValue(2, 1, new Date (1988,0,1));
data.setValue(2, 2, 300);
data.setValue(2, 3, 250);
data.setValue(2, 4, "West");
data.setValue(3, 0, "Apples");
data.setValue(3, 1, new Date (1989,6,1));
data.setValue(3, 2, 1200);
data.setValue(3, 3, 400);
data.setValue(3, 4, "East");
data.setValue(4, 0, "Oranges");
data.setValue(4, 1, new Date (1989,6,1));
data.setValue(4, 2, 750);
data.setValue(4, 3, 150);
data.setValue(4, 4, "West");
data.setValue(5, 0, "Bananas");
data.setValue(5, 1, new Date (1989,6,1));
data.setValue(5, 2, 788);
data.setValue(5, 3, 617);
data.setValue(5, 4, "West");
return data;
}
}

关于java - 如何设置 Google 可视化动态图表的状态?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4803505/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com