- GWT Highcharts 教程
- GWT Highcharts - 主頁
- GWT Highcharts - 概覽
- 環境設定
- 配置語法
- GWT Highcharts - 線形圖表
- GWT Highcharts - 面積圖
- GWT Highcharts - 條形圖
- GWT Highcharts - 柱形圖
- GWT Highcharts - 餅圖
- GWT Highcharts - 散點圖
- GWT Highcharts - 動態圖表
- GWT Highcharts - 組合
- GWT Highcharts - 3D 圖表
- GWT Highcharts - 地圖圖表
- GWT Highcharts 有用資源
- GWT Highcharts - 快速指南
- GWT Highcharts - 有用資源
- GWT Highcharts - 討論
時間序列,可縮放圖表
我們在 Highcharts 配置語法 章節中已瞭解用於繪製此圖表的配置。我們現在考慮一下以下示例,以進一步瞭解時間序列,可縮放圖表。
配置
現在,我們討論一下所採取的附加配置/步驟。
圖表
配置圖表使其可縮放。chart.zoomType 決定了使用者可透過拖動滑鼠縮放的維度。此處的可能值為 x、y 或 xy。
chart.setZoomType(BaseChart.ZoomType.X)
繪圖選項
使用 plotOptions 配置圖表區域。
chart.setAreaPlotOptions(new AreaPlotOptions()
.setFillColor(new Color()
.setLinearGradient(0, 0, 0, 1)
.addColorStop(0, 69, 114, 167)
.addColorStop(1, 2, 0, 0, 0)
)
.setMarker(new Marker()
.setEnabled(false)
.setHoverState(new Marker()
.setEnabled(true)
.setRadius(5)
)
)
.setShadow(false)
.setHoverStateLineWidth(1)
);
示例
HelloWorld.java
package com.tutorialspoint.client;
import org.moxieapps.gwt.highcharts.client.Axis;
import org.moxieapps.gwt.highcharts.client.BaseChart;
import org.moxieapps.gwt.highcharts.client.Chart;
import org.moxieapps.gwt.highcharts.client.Color;
import org.moxieapps.gwt.highcharts.client.Legend;
import org.moxieapps.gwt.highcharts.client.Series;
import org.moxieapps.gwt.highcharts.client.ToolTip;
import org.moxieapps.gwt.highcharts.client.plotOptions.AreaPlotOptions;
import org.moxieapps.gwt.highcharts.client.plotOptions.Marker;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.i18n.client.DateTimeFormat;
import com.google.gwt.user.client.ui.RootPanel;
public class HelloWorld implements EntryPoint {
public void onModuleLoad() {
Chart chart = new Chart()
.setZoomType(BaseChart.ZoomType.X)
.setSpacingRight(20)
.setChartTitleText("USD to EUR exchange rate from 2006 through 2008")
.setChartSubtitleText("Click and drag in the plot area to zoom in")
.setLegend(new Legend()
.setEnabled(false))
.setToolTip(new ToolTip()
.setShared(true)
)
.setLegend(new Legend()
.setEnabled(false)
)
.setAreaPlotOptions(new AreaPlotOptions()
.setFillColor(new Color()
.setLinearGradient(0, 0, 0, 1)
.addColorStop(0, 69, 114, 167)
.addColorStop(1, 2, 0, 0, 0)
)
.setMarker(new Marker()
.setEnabled(false)
.setHoverState(new Marker()
.setEnabled(true)
.setRadius(5)
)
)
.setShadow(false)
.setHoverStateLineWidth(1)
);
chart.getXAxis()
.setType(Axis.Type.DATE_TIME)
.setMaxZoom(14 * 24 * 3600000) //fourteen days
.setAxisTitleText(null);
chart.getYAxis()
.setAxisTitleText("Exchange rate")
.setMin(0.6)
.setStartOnTick(false)
.setShowFirstLabel(false);
chart.addSeries(chart.createSeries()
.setType(Series.Type.AREA)
.setName("USD to EUR")
.setPlotOptions(new AreaPlotOptions()
.setPointInterval(24 * 3600 * 1000)
.setPointStart(getTime("2006-01-01"))
)
.setPoints(new Number[] {
0.8446, 0.8445, 0.8444, 0.8451, 0.8418, 0.8264, 0.8258, 0.8232,
0.7158, 0.714, 0.7119, 0.7129, 0.7129, 0.7049, 0.7095
})
);
RootPanel.get().add(chart);
}
private static final DateTimeFormat dateTimeFormat = DateTimeFormat.getFormat("yyyy-MM-dd");
private long getTime(String date) {
return dateTimeFormat.parse(date).getTime();
}
}
結果
驗證結果。
gwt_highcharts_line_charts.htm
廣告