GWT:在 GWTHighCharts 中创建一个简单的气象图

发布于 2025-01-01 02:26:17 字数 3826 浏览 0 评论 0 原文

我正在尝试构建一个气象图 this

在此图表中,下面的 xaxis 的值如下00,06,12,18
这些都很好,但我如何添加上述值,如 satNov14、sunNov15、MonNov16,

因为有多个 Y 轴但没有多个 x 轴。

我正在尝试这个,但在那之后我没有按正确的顺序获得上述日期

                 final Chart chart = new Chart()  

    .setBorderColor("#C7D5D5")
    .setBorderWidth(3)
    .setBorderRadius(0)
    .setBackgroundColor("#FFFFFF")
    .setChartTitleText("Meteogram")  
    .setSpacingTop(5)
    .setChartSubtitleText("yr.no")
    .setColumnPlotOptions(new ColumnPlotOptions()  

    .setDataLabels(new DataLabels()  
    .setEnabled(true)  
    ) )


    .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.getXAsString() + ": " +  
                toolTipData.getYAsLong();  
            }  
            return s;  

        }  
    })  
    )  
    .setLabelItems(  
            new LabelItem()  
            .setHtml("")  
            .setStyle(new Style()  
            .setLeft("40px")  
            .setTop("8px")  
            .setColor("black")  
            )  
    );  

    // Primary yAxis  
    chart.getYAxis(0).setGridLineWidth(1).setAxisTitleText("test")
    .setAxisTitle(new AxisTitle()  
    .setText("") 

    )  
    .setLabels(new YAxisLabels()  
    ////                .setStyle(new Style()  
    ////                    .setColor("#89A54E")  
    //                )  
    .setFormatter(new AxisLabelsFormatter() {  
        public String format(AxisLabelsData axisLabelsData) {  
            return axisLabelsData.getValueAsLong() + "°";  
        }  
    })  
    );  

    // Secondary yAxis  
    chart.getYAxis(1).setGridLineWidth(2)  
    .setAxisTitle(new AxisTitle()  
    .setText("")  
    )  
    .setOpposite(true)  
    .setLabels(new YAxisLabels()  
    .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).setLinkedTo(0)

    .setOpposite(true) 


    .setCategories("Sat Nov13", "Sat Nov14", "Sat Nov15", "Sat Nov16"); 

    chart.getXAxis(0).setGridLineWidth(1)
    .setCategories("18","00","06","12","18","00","06","12","18","00","06","12","18","00","06","12","18") ;



    chart.addSeries(chart.createSeries()
            .setName("")  

            .setType(Series.Type.COLUMN)
            .setPlotOptions(new ColumnPlotOptions()  
            .setColor("#24CBE5"))

            .setPoints(new Number[]{  
                    0,0,0,3,5,3,0,1,3,1,0,0,0,0}
            )  
            .setYAxis(1) 
    );

    chart.addSeries(chart.createSeries()  
            .setName("")  
            .setType(Series.Type.SPLINE)
            .setPoints(new Number[]{  
                    5,4.5,4,5,1,0,0,0,3,5,6,3,7,2 })
                    .setPlotOptions(new ColumnPlotOptions() 
                    .setMarker(m1)

                    .setColor("#4572A7"))

    ); 
    return chart;  
}

附件是我的输出

任何建议

谢谢

i am trying to build a meteogram as this

In this chart there's xaxis below with values like 00,06,12,18
These are fine but how can i add the above values like satNov14, sunNov15, MonNov16

as there's multiple Yaxis but no multiple xaxis.

I am trying this , but after that am not getting the above dates in proper order

                 final Chart chart = new Chart()  

    .setBorderColor("#C7D5D5")
    .setBorderWidth(3)
    .setBorderRadius(0)
    .setBackgroundColor("#FFFFFF")
    .setChartTitleText("Meteogram")  
    .setSpacingTop(5)
    .setChartSubtitleText("yr.no")
    .setColumnPlotOptions(new ColumnPlotOptions()  

    .setDataLabels(new DataLabels()  
    .setEnabled(true)  
    ) )


    .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.getXAsString() + ": " +  
                toolTipData.getYAsLong();  
            }  
            return s;  

        }  
    })  
    )  
    .setLabelItems(  
            new LabelItem()  
            .setHtml("")  
            .setStyle(new Style()  
            .setLeft("40px")  
            .setTop("8px")  
            .setColor("black")  
            )  
    );  

    // Primary yAxis  
    chart.getYAxis(0).setGridLineWidth(1).setAxisTitleText("test")
    .setAxisTitle(new AxisTitle()  
    .setText("") 

    )  
    .setLabels(new YAxisLabels()  
    ////                .setStyle(new Style()  
    ////                    .setColor("#89A54E")  
    //                )  
    .setFormatter(new AxisLabelsFormatter() {  
        public String format(AxisLabelsData axisLabelsData) {  
            return axisLabelsData.getValueAsLong() + "°";  
        }  
    })  
    );  

    // Secondary yAxis  
    chart.getYAxis(1).setGridLineWidth(2)  
    .setAxisTitle(new AxisTitle()  
    .setText("")  
    )  
    .setOpposite(true)  
    .setLabels(new YAxisLabels()  
    .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).setLinkedTo(0)

    .setOpposite(true) 


    .setCategories("Sat Nov13", "Sat Nov14", "Sat Nov15", "Sat Nov16"); 

    chart.getXAxis(0).setGridLineWidth(1)
    .setCategories("18","00","06","12","18","00","06","12","18","00","06","12","18","00","06","12","18") ;



    chart.addSeries(chart.createSeries()
            .setName("")  

            .setType(Series.Type.COLUMN)
            .setPlotOptions(new ColumnPlotOptions()  
            .setColor("#24CBE5"))

            .setPoints(new Number[]{  
                    0,0,0,3,5,3,0,1,3,1,0,0,0,0}
            )  
            .setYAxis(1) 
    );

    chart.addSeries(chart.createSeries()  
            .setName("")  
            .setType(Series.Type.SPLINE)
            .setPoints(new Number[]{  
                    5,4.5,4,5,1,0,0,0,3,5,6,3,7,2 })
                    .setPlotOptions(new ColumnPlotOptions() 
                    .setMarker(m1)

                    .setColor("#4572A7"))

    ); 
    return chart;  
}

Attached is my outputenter image description here

Any Suggestions

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

夏日浅笑〃 2025-01-08 02:26:17

就像 @Strelok 所说,如果右键单击页面并查看源代码,代码位于

xAxis: [
{ 
  type: 'datetime',
  tickInterval: 6 * 3600 * 1000,
  tickPosition: 'inside',
  tickLength: 30,
  gridLineWidth: 1,
  gridLineColor: '#F0F0F0',
  startOnTick: false,
  endOnTick: false,
  minPadding: 0,
  maxPadding: 0,
  offset: 30,
  showLastLabel: true,
  labels: {
    formatter: function(){
      return Highcharts.dateFormat('%H', this.value);
    }
  }
}, 
{ 
  linkedTo: 0,
  tickInterval: 24 * 3600 * 1000,
  labels: {
  formatter: function(){
    return Highcharts.dateFormat(
      '<span style="font-size: 12px; font-weight: bold">%a</span>, %b %e', this.value);
    },
    align: 'left',
    x: 3
  },
  opposite: true,
  tickLength: 20,
  gridLineWidth: 1
}],

从外观上看,顶部用于底部标签,底部用于顶部标签。

编辑:

试一试。

chart.getXAxis(1)
    .setLinkedTo(0)
    .setGridLineWidth(1)
    .setOpposite(true) 
    .setTickInterval(24 * 3600 * 1000) // 24 hour tick intervals
    .setCategories("Sat Nov13", "Sat Nov14", "Sat Nov15", "Sat Nov16"); 

chart.getXAxis(0)
    .setGridLineWidth(1)
    .setCategories("18","00","06","12","18","00","06","12","18","00","06","12","18","00","06","12","18");
    .setTickInterval(6 * 3600 * 1000) // 6 hour tick intervals
    .setTickPosition("inside")
    .setStartOnTick(false)
    .setEndOnTick(false)
    .setOffset(30)
    .setShowLastLabel(true)

Like @Strelok said, the code is in the <script> tag if you right click the page and view source.

xAxis: [
{ 
  type: 'datetime',
  tickInterval: 6 * 3600 * 1000,
  tickPosition: 'inside',
  tickLength: 30,
  gridLineWidth: 1,
  gridLineColor: '#F0F0F0',
  startOnTick: false,
  endOnTick: false,
  minPadding: 0,
  maxPadding: 0,
  offset: 30,
  showLastLabel: true,
  labels: {
    formatter: function(){
      return Highcharts.dateFormat('%H', this.value);
    }
  }
}, 
{ 
  linkedTo: 0,
  tickInterval: 24 * 3600 * 1000,
  labels: {
  formatter: function(){
    return Highcharts.dateFormat(
      '<span style="font-size: 12px; font-weight: bold">%a</span>, %b %e', this.value);
    },
    align: 'left',
    x: 3
  },
  opposite: true,
  tickLength: 20,
  gridLineWidth: 1
}],

Top part is for bottom labels, bottom part is for top labels from the looks of it.

edit:

Give this a shot.

chart.getXAxis(1)
    .setLinkedTo(0)
    .setGridLineWidth(1)
    .setOpposite(true) 
    .setTickInterval(24 * 3600 * 1000) // 24 hour tick intervals
    .setCategories("Sat Nov13", "Sat Nov14", "Sat Nov15", "Sat Nov16"); 

chart.getXAxis(0)
    .setGridLineWidth(1)
    .setCategories("18","00","06","12","18","00","06","12","18","00","06","12","18","00","06","12","18");
    .setTickInterval(6 * 3600 * 1000) // 6 hour tick intervals
    .setTickPosition("inside")
    .setStartOnTick(false)
    .setEndOnTick(false)
    .setOffset(30)
    .setShowLastLabel(true)
抹茶夏天i‖ 2025-01-08 02:26:17

如果您对日期使用 unix 纪元时间戳,并且需要以日期格式显示时间戳 - 只需将轴的类型设置为日期时间

例如:
x轴:{
类型:'日期时间'
}
});

检查这个小提琴: http://jsfiddle.net/HnwbQ/1/

参考:http://www.highcharts.com/ref/#xAxis--type

in case you use unix epoch timestamps for your dates and if you need it the timestamp to be displayed in date format - just set the type of the axis to datetime

for example:
xAxis: {
type: 'datetime'
}
});

check this fiddle: http://jsfiddle.net/HnwbQ/1/

reference: http://www.highcharts.com/ref/#xAxis--type

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文