我在GWT Highcharts中制作了一个气象图
这是我得到的
正如你在我的图表中看到的那样,滴答线出现在5sept,6sept等之上,并且这些蓝色列也没有正确对齐,就像它们不应该在线上方一样。 似乎一切都需要在右侧,但无法弄清楚如何'
任何想法
下面是我的代码
public Chart createChart() {
btnChart.setEnabled(false);
final Chart chart = new Chart()
.setBorderColor("#C7D5D5")
.setBorderWidth(3)
.setBorderRadius(0)
.setBackgroundColor("#FFFFFF").setOption("#FFFFFF", new Color()
.setLinearGradient(0, 25, 0, 25.1)
.addColorStop(0, "#C7D5D5")
.addColorStop(1, "white"))
.setChartTitleText("Meteogram")
.setSpacingTop(5)
.setChartSubtitleText("yr.no")
.setColumnPlotOptions(new ColumnPlotOptions()
)
.setToolTip(new ToolTip()
.setFormatter(new ToolTipFormatter() {
public String format(ToolTipData toolTipData) {
String s;
if (toolTipData.getPointName() != null) {
s = toolTipData.getPointName() + ": " +
toolTipData.getYAsLong() + " ,";
} else {
s = toolTipData.getXAsLong()+ ": " +
toolTipData.getYAsLong();
}
return s;
}
})
)
.setLabelItems(
new LabelItem()
.setHtml("")
.setStyle(new Style()
.setLeft("40px")
.setTop("8px")
.setColor("black")
)
);
// TO UNCOMMENT
// Primary yAxis
chart.getYAxis(0).setGridLineWidth(1).setAxisTitleText("")
.setAxisTitle(new AxisTitle()
.setText(""))
.setGridLineColor("#F0F0F0")
.setMaxPadding(0.3)
.setLabels(new YAxisLabels()
.setStyle(new Style()
.setFontSize("10px")
)
// .setX(-3)
.setFormatter(new AxisLabelsFormatter() {
public String format(AxisLabelsData axisLabelsData) {
return axisLabelsData.getValueAsLong() + "°";
}
})
);
chart.getYAxis(0).createPlotLine()
.setColor("#C0C0C0")
.setWidth(1)
.setValue(0);
// Secondary yAxis
chart.getYAxis(1).setGridLineWidth(0)
.setAxisTitle(new AxisTitle()
.setText("")
)
.setOpposite(true)
.setLinkedTo(0)
.setGridLineWidth(0)
.setMaxPadding(0.3)
.setLabels(new YAxisLabels()
.setStyle(new Style()
.setFontSize("10px")
)
// .setX(3)
// .setEnabled(false)
.setFormatter(new AxisLabelsFormatter() {
public String format(AxisLabelsData axisLabelsData) {
return axisLabelsData.getValueAsLong() + "°";
}
})
);
Point p1 = new Point(5, 5);
Marker m = new Marker();
m.setEnabled(true);
m.setOption("symbol", "url(41.png)");
p1.setMarker(m);
Point p2 = new Point(4.5, 4.5);
p2.setMarker(m);
Point p3 = new Point(4, 4);
Marker m1 = new Marker();
m1.setEnabled(true);
m1.setOption("symbol", "url(41.png)");
p3.setMarker(m1);
chart.getXAxis(1).setGridLineWidth(1)
.setType(Type.DATE_TIME)
.setLinkedTo(0)
.setTickInterval(24 * 3600 * 1000)
.setOpposite(true)
.setTickLength(20)
.setGridLineWidth(1)
;
chart.getXAxis(0).setGridLineWidth(1)
.setType(Axis.Type.DATE_TIME)
.setTickInterval( 6 * 3600 * 1000)
.setTickPosition(TickPosition.INSIDE)
.setTickLength(30)
.setGridLineWidth(1)
.setGridLineColor("#F0F0F0")
.setStartOnTick(false)
.setEndOnTick(false)
.setMinPadding(0)
.setMaxPadding(0)
.setOffset(30)
.setShowLastLabel(true);
chart.addSeries(chart.createSeries()
.setName("")
// .setYAxis(2)
.setType(Series.Type.COLUMN)
.setPlotOptions(new ColumnPlotOptions()
.setColor("#68CFE8"))
.setPlotOptions(new ColumnPlotOptions()
.setPointPadding(0)
.setGroupPadding(0)
.setBorderWidth(0)
.setDataLabels(new DataLabels()
.setEnabled(true)
)
)
.setPoints(new Number[][]{
{getTime("2010-09-04 18:30"), 0},
{getTime("2010-09-05 00:10"), 0},
{getTime("2010-09-05 06:10"), 0},
{getTime("2010-09-05 12:10"), 1.6},
{getTime("2010-09-05 18:10"), 2.4},
{getTime("2010-09-06 00:10"), 3.1},
{getTime("2010-09-06 06:10"), 0},
// {getTime("2010-09-06 12:10"), 0.5},
{getTime("2010-09-06 18:10"), 1.6},
{getTime("2010-09-07 00:10"), 0.3},
{getTime("2010-09-07 06:10"), 0},
{getTime("2010-09-07 12:10"), 0},
{getTime("2010-09-07 18:10"), 0},
{getTime("2010-09-08 00:10"), 0},
{getTime("2010-09-08 06:10"), 0},
{getTime("2010-09-08 12:10"), 0},
{getTime("2010-09-08 18:10"), 0},
}
)
.setYAxis(1)
);
chart.addSeries(chart.createSeries()
.setName("")
.setType(Series.Type.SPLINE)
.setPoints(new Number[][]{
{getTime("2010-09-04 18:10"), 3},
{getTime("2010-09-05 00:10"), 3.5},
{getTime("2010-09-05 06:10"), 4},
{getTime("2010-09-05 12:10"), 3.6},
{getTime("2010-09-05 18:10"), 3.4},
{getTime("2010-09-06 00:10"), 2.6},
{getTime("2010-09-06 06:10"), 1},
{getTime("2010-09-06 12:10"), 3.5},
{getTime("2010-09-06 18:10"), 2.6},
{getTime("2010-09-07 00:10"), 1.3},
{getTime("2010-09-07 06:10"), 2.3},
{getTime("2010-09-07 12:10"), 3.1},
{getTime("2010-09-07 18:10"), 3.4},
{getTime("2010-09-08 00:10"), 3},
{getTime("2010-09-08 06:10"), 2.5},
{getTime("2010-09-08 12:10"), 3.1},
{getTime("2010-09-08 18:10"), 3.2},
})
.setPlotOptions(new ColumnPlotOptions()
.setMarker(m1)
// .setMarker("http://symbol.yr.no/grafikk/sym/b38/'+ symbols[i] +'.png'")
.setZIndex(1)
.setColor("#4572A7"))
);
return chart;
}
private long getTime(String date) {
return dateTimeFormat.parse(date).getTime();
}
static final DateTimeFormat dateTimeFormat = DateTimeFormat.getFormat("yyyy-MM-dd hh:mm");
}