2012-03-23 60 views
3

現在、一連のジョブの実行時間を示すGWTビジュアライゼーションライブラリで線グラフグラフを生成しています。時間の値はミリ秒単位で、ミリ秒ではなく時間:分:秒の形式でグラフにy軸のラベルを表示します。私はこの変換を行うためにsetFormattedValueメソッドを使用しましたが、y軸がミリ秒単位で表示されている間残念ながら、ツールチップ値のみが書式設定された値を表示します。GWT視覚化のY軸形式をミリ秒から時間に変更します。min:sec

import java.util.Collection; 
import java.util.HashMap; 
import java.util.Iterator; 

import com.electriccloud.commander.gwt.client.util.CommanderUrlBuilder; 
import com.google.gwt.user.client.ui.HorizontalPanel; 
import com.google.gwt.user.client.ui.Label; 
import com.google.gwt.user.client.ui.VerticalPanel; 
import com.google.gwt.user.client.ui.Widget; 
import com.google.gwt.visualization.client.AbstractDataTable; 
import com.google.gwt.visualization.client.AbstractDataTable.ColumnType; 
import com.google.gwt.visualization.client.DataTable; 
import com.google.gwt.visualization.client.VisualizationUtils; 
import com.google.gwt.visualization.client.visualizations.Table; 
import com.google.gwt.visualization.client.visualizations.corechart.HorizontalAxisOptions; 
import com.google.gwt.visualization.client.visualizations.corechart.LineChart; 




public class ScheduledJobMonitorFancyChartPanel extends HorizontalPanel{ 

    protected static final int MS = 0; 
    protected static final int HR_MIN_SEC = 1; 
    private String scheduleName; 
    private HashMap<String, AverageElapsedTime> elapsedTimeData; 
    private Table dataTable; 
    private LineChart lineChart; 
    private boolean graphIsVisible = true; 
    private int displayStyle; 


    public ScheduledJobMonitorFancyChartPanel(){ 
     super(); 
     this.setStyleName("hidden"); 
    } 

    public ScheduledJobMonitorFancyChartPanel(String schedName, HashMap<String, AverageElapsedTime> data, int displayType){ 
     this(); 
     this.scheduleName = schedName; 
     this.elapsedTimeData = data; 
     this.displayStyle = displayType; 
     createTableAndChart(); 
     this.setVisible(graphIsVisible); 
    } 

    private void createTableAndChart(){ 
     // this block defines the table and chart 
     Runnable onLoadCallback = new Runnable() { 
      public void run() { 
       VerticalPanel outterPanel = new VerticalPanel(); 
       Label chartTitle = new Label("ElapsedTime Data for " + scheduleName); 
       chartTitle.setStylePrimaryName("chartTitle"); 
       outterPanel.add(chartTitle); 
       HorizontalPanel allChartGroups = new HorizontalPanel(); 
        allChartGroups.setStylePrimaryName("allChartGroupsStyle"); 

       // Since a single Job may have multiple steps being monitored, this creates the charts 
       // for each step, but groups them all (horizontally) under the same job 
       Collection<String> c = elapsedTimeData.keySet(); 
       Iterator<String> itr = c.iterator(); 

       while(itr.hasNext()){ 
        String stepName = itr.next(); 
        AverageElapsedTime aet = elapsedTimeData.get(stepName); 
        AbstractDataTable linkableTable = createTableWithLinks(aet); 
        AbstractDataTable table = createTable(aet); 

        dataTable = new Table(linkableTable, createDataTableOptions()); 
         dataTable.setStylePrimaryName("dataTableStyle"); 

        lineChart = new LineChart(table, createLineChartOptions(stepName)); 
         lineChart.setStylePrimaryName("lineChartStyle"); 


        HorizontalPanel tableAndChartGroup = new HorizontalPanel(); 
         tableAndChartGroup.setStylePrimaryName("tableAndChartGroup"); 
         tableAndChartGroup.add(dataTable); 
         tableAndChartGroup.add(lineChart); 

        allChartGroups.add(tableAndChartGroup); 
       } 

       outterPanel.add(allChartGroups); 
       addToPanel(outterPanel); 
      } 
     }; 
     // this line gets the table/chart defined above displayed on the screen 
     VisualizationUtils.loadVisualizationApi(onLoadCallback, LineChart.PACKAGE, Table.PACKAGE); 
    } 

    // Because the table/chart is created inside an annonymous Runnable object, this method 
    // exposes it to being added to "this" 
    private void addToPanel(Widget widget){ 
     this.add(widget); 
    } 

    // set up the table used by the LineChart 
    private AbstractDataTable createTable(AverageElapsedTime aet){ 
     DataTable data = DataTable.create(); 

     data.addColumn(ColumnType.STRING, "JobId"); 
     data.addColumn(ColumnType.NUMBER, "ElapsedTime"); 

     data.addRows(aet.getSize()); 

     HashMap<Long, Long> jobIdElapsedTimeHash = aet.getListOfTimes(); 
     Collection<Long> c = jobIdElapsedTimeHash.keySet(); 
     Iterator<Long> itr = c.iterator(); 
     int row = 0; 
     while(itr.hasNext()){ 
      Long jobId = itr.next(); 
      data.setValue(row, 0, jobId.toString()); 
      if(this.displayStyle == ScheduledJobMonitorFancyChartPanel.MS) 
       data.setValue(row, 1, jobIdElapsedTimeHash.get(jobId)); 
      else if(this.displayStyle == ScheduledJobMonitorFancyChartPanel.HR_MIN_SEC){ 
       data.setValue(row, 1, jobIdElapsedTimeHash.get(jobId)); 
       String formattedValue = AverageElapsedTime.getDisplayTime(jobIdElapsedTimeHash.get(jobId)); 
       data.setFormattedValue(row, 1, formattedValue); 
      } 
      row++; 
     } 

     return data; 
    } 

    // set up the table used by the DataTable - It embeds links to the jobId listed 
    private AbstractDataTable createTableWithLinks(AverageElapsedTime aet){ 
     DataTable data = DataTable.create(); 

     data.addColumn(ColumnType.STRING, "JobId"); 
     data.addColumn(ColumnType.NUMBER, "ElapsedTime"); 

     data.addRows(aet.getSize()); 

     HashMap<Long, Long> jobIdElapsedTimeHash = aet.getListOfTimes(); 
     Collection<Long> c = jobIdElapsedTimeHash.keySet(); 
     Iterator<Long> itr = c.iterator(); 
     String urlBase = CommanderUrlBuilder.getBase(); 
     int row = 0; 
     while(itr.hasNext()){ 
      Long jobId = itr.next(); 
      data.setValue(row, 0, "<a href='" + urlBase + "link/jobDetails/jobs/" + jobId + "' target='_blank'>" + jobId + "</a>"); 
//   data.setValue(row, 1, jobIdElapsedTimeHash.get(jobId)); 
      if(this.displayStyle == ScheduledJobMonitorFancyChartPanel.MS) 
       data.setValue(row, 1, jobIdElapsedTimeHash.get(jobId)); 
      else if(this.displayStyle == ScheduledJobMonitorFancyChartPanel.HR_MIN_SEC){ 
       data.setValue(row, 1, jobIdElapsedTimeHash.get(jobId)); 
       String formattedValue = AverageElapsedTime.getDisplayTime(jobIdElapsedTimeHash.get(jobId)); 
       data.setFormattedValue(row, 1, formattedValue); 
      } 
      row++; 
     } 

     return data; 
    } 

    // set the options for the DataTable 
    private Table.Options createDataTableOptions(){ 
     Table.Options options = Table.Options.create(); 
     options.setHeight("300"); 
     options.setWidth("190"); 
     options.setAllowHtml(true); 
     return options; 
    } 


    // set the options for the LineChart 
    private com.google.gwt.visualization.client.visualizations.corechart.Options createLineChartOptions(String stepName){ 
     com.google.gwt.visualization.client.visualizations.corechart.Options options = com.google.gwt.visualization.client.visualizations.corechart.Options.create(); 
     options.setWidth(500); 
     options.setHeight(300); 
     options.setCurveType("function"); 
     options.setColors("#336E95"); 
     options.setTitle(stepName); 
     HorizontalAxisOptions hao = HorizontalAxisOptions.create(); 
     hao.setSlantedText(true); 
     hao.setSlantedTextAngle(45); 
     options.setHAxisOptions(hao); 
     return options; 
    } 

    public void setTimeDisplay(int displayType) { 
     switch(displayType){ 
     case 0: 
      break; 
     case 1: 
      this.displayStyle = ScheduledJobMonitorFancyChartPanel.HR_MIN_SEC; 
     } 

    } 
} 

答えて

0

私は手でコードを持っていない:

は、ここに私のコードです。

GWT用Google Graphs APIのドキュメントはまだ完成していないことを覚えています。 JavaScriptグラフの上にあるラッパーであることを知る必要があります。 これは、セッターで直接設定できるオプションがいくつかあることを意味します。いくつかのオプションでは、JSライブラリのパラメータを調べて、何らかの形でジェネリックオプションセッターを挿入する必要があります(軸上のオプションを " >価値 "ベース)。ここで

あなたはJSライブラリのパラメータの説明を見つけることができます。 https://developers.google.com/chart/interactive/docs/gallery/areachart#Data_Format

あなたが「hAxis.format」を見れば、あなたはおそらく、あなたが探しているものを見つけることができます。

編集: 答えを完成させるには、HorizontalAxisOptions classとそのsetメソッドを使用する必要があります。 送信するフォーマットが厄介で、間違っているとエラーが発生しないように注意してください。set("hAxis.format", "{format:'HH:mm:ss'}");

関連する問題