有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java gwtcharts库未打印图形

我正在用GWT和GWT图表库开发GUI。但是,当打印图形时,应用程序被锁定,屏幕上不会显示任何内容。代码如下:

public HorizontalPanel printGraph(Map<String, Map<String, Map<String, String>>> hmMonthData, String sSelectedZone){
    atlHorizontalPanel.setSpacing(15);
    atlHorizontalPanel.setBorderWidth(0);

    //If the data is not collected, no graph should be displayed
    if(hmMonthData.size() > 0){

        //Get the list of values of the sensors in the Zone visible in the stack panel
        final Map<String, Map<String,String>> hmSensorsByZone = hmMonthData.get(sSelectedZone);

        //Get the list of sensors associated to the Zone selected
        Object[] asSensors = hmSensorsByZone.keySet().toArray();

        //Only if the length of sensors is upper than 0
        if(asSensors.length > 0){

            final List<String> lsSensors = new ArrayList<String>();

            for(int i = 0; i < asSensors.length; i++){
                lsSensors.add(asSensors[i].toString());
            }

            //Creating the chart
            ChartLoader chartLoader = new ChartLoader(ChartPackage.CORECHART);
            chartLoader.loadApi(new Runnable() {
                @Override
                public void run() {
                    // call method to create and show the chart
                    DataTable dataTable = DataTable.create();

                    //Columnas a mostrar, la primera para el eje de abscisas (fecha) y la segunda para
                    //los valores en el eje de ordenadas
                    dataTable.addColumn(ColumnType.DATE, "Date");

                    for(String sSensor : lsSensors){
                        dataTable.addColumn(ColumnType.NUMBER, sSensor);
                    }

                    DateTimeFormat dtf = DateTimeFormat.getFormat("dd/MM/yy hh:mm:ss");

                    //Se añaden los valores y los puntos para dibujar la gráfica
                    for(int j = 0; j < lsSensors.size(); j++){
                        //Delete all the rows related to the sensor j

                        Map<String,String> hmValues = hmSensorsByZone.get(lsSensors.get(j));

                        //Only if the size of the values is upper than 0
                        if(hmValues.size() > 0){

                            Object[] asTimestamps = (Object[]) hmValues.keySet().toArray(); 
                            Object[] asValues = (Object[]) hmValues.values().toArray(); 

                            if(dataTable.getNumberOfRows() < asTimestamps.length)
                                dataTable.addRows(asTimestamps.length - dataTable.getNumberOfRows()); 

                            for(int i = 0; i < asTimestamps.length; i++){
                                String sTimestamp = asTimestamps[i].toString();
                                String sValue = asValues[i].toString();
                                Double dValue = Double.valueOf(sValue);

                                dataTable.setValue(i, 0,    dtf.parse(sTimestamp)); 
                                dataTable.setValue(i, j+1, dValue);
                            }
                        }
                    }

                    LineChartOptions options = LineChartOptions.create();
                    options.setAxisTitlesPosition(AxisTitlesPosition.IN);
                    ChartArea chartArea = ChartArea.create(); 
                    chartArea.setWidth(500);
                    chartArea.setHeight(350);
                    options.setChartArea(chartArea);

                    LineChart lineChart = new LineChart();
                    lineChart.draw(dataTable, options);

                    atlHorizontalPanel.add(lineChart);

                }
            });
        }   
    }
    else{
        //Creating the chart
        ChartLoader chartLoader = new ChartLoader(ChartPackage.CORECHART);
        chartLoader.loadApi(new Runnable() {
            @Override
            public void run() {
                // call method to create and show the chart
                DataTable data = DataTable.create();
                data.addColumn(ColumnType.DATE, "Date");
                data.addColumn(ColumnType.NUMBER, "Value");
                data.addRows(1);
                DateTimeFormat dtf = DateTimeFormat.getFormat("yyyy.MM.dd hh:mm");
                data.setValue(0, 0, dtf.parse("2014.01.01 00:00")); 

                LineChartOptions options = LineChartOptions.create();
                options.setAxisTitlesPosition(AxisTitlesPosition.IN);
                ChartArea chartArea = ChartArea.create(); 
                chartArea.setWidth(500);
                chartArea.setHeight(350);
                options.setChartArea(chartArea);

                LineChart lineChart = new LineChart();
                lineChart.draw(data, options);

                atlHorizontalPanel.add(lineChart);

            }
        });
    }

    return atlHorizontalPanel;
}

我是这个图书馆的新手,那么,我做错了什么?先谢谢你


共 (0) 个答案