2016-04-13 53 views
3

DB Table Structure谷歌可視化數據的String列編組

data_MONTHMONTHTEST = new google.visualization.DataTable(); 

data_MONTHMONTHTEST.addColumn('number','id');//0 
data_MONTHMONTHTEST.addColumn('string','month');//1 
data_MONTHMONTHTEST.addColumn('number','revenue');//2 

var aggView_MONTHMONTHTEST_month =google.visualization.data.group(data_MONTHMONTHTEST, [1],[{'column':2, 'aggregation':google.visualization.data.sum, 'type': 'number',label:'revenue'}]); 


barChart_MONTHMONTHTEST_month = new google.visualization.ChartWrapper(
{ 
    'chartType':'BarChart', 
    'containerId': 'chart_div_bar_MONTHMONTHTEST0', 
    'options': barOptions_MONTHMONTHTEST_month , 
    dataTable: aggView_MONTHMONTHTEST_month 
});    

當上午繪製圖表一個月列值沒有得到保留。而是根據字母順序篡改圖表。

我試過排序:作爲選項列表的一部分禁用,但沒有運氣。

有人可以建議如何保存月份順序。

在此先感謝.. !!

回答

0

'month'

data_MONTHMONTHTEST.addColumn('number','id');//0 
data_MONTHMONTHTEST.addColumn('number','month');//1 
data_MONTHMONTHTEST.addColumn('number','revenue');//2 

使用類型'number'(相對於'string')然後使用格式化的值來顯示名稱。

沒有您的數據加載 - 但該列的值將改變
來源:'March'
要:{v: 2, f: 'March'} // 2 for zero based months -- 3 works too

,或者您可以使用的方法......

data_MONTHMONTHTEST.setCell(row, col, 2, 'March'); 

或...

data_MONTHMONTHTEST.setValue(row, col, 2); 
data_MONTHMONTHTEST.setFormattedValue(row, col, 'March'); 
+0

感謝您的回答。在mycase中,我通過xml通過dinamically添加行。 –

1

我們可以使用列索引如下:每日研究後,我發現一個選項來禁用該列排序

var aggView_MONTHMONTHTEST_month = google.visualization.data.group(data_MONTHMONTHTEST123, [1],[{'column':2, 'aggregation':google.visualization.data.sum, 'type': 'number',label:'revenue'}]);     

aggView_MONTHMONTHTEST_month.sort({column: 1, sort: 'disable'}); 
0
It worked for me Bar chart.Here is the code 
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/1.0.2/Chart.min.js"></script> 
    <script src="https://code.jquery.com/jquery-2.2.1.js"></script> 
    <script src="Js/jquery-1.4.1-vsdoc.js"></script> 
    <script src="Js/jquery-1.4.1.js"></script>                     
    <script src="http://www.google.com/jsapi" type="text/javascript"></script> 
    <script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script> 
    <script src="Js/jquery-1.4.1.min.js"></script> 
     <script type="text/javascript"> 
      google.load('visualization', '1', { packages: ['corechart'] }); 
      //google.charts.load('current', {'packages':['bar']}); 
      //google.charts.setOnLoadCallback(drawChart); 
     </script> 
---here is the CS file 
    //GetDataperformance for JQgrid On load Event 
     [WebMethod(EnableSession = true)] 
     public static List<Dictionary<string, object>> GetDataperformance() 
     { 
      List<Dictionary<string, object>> rows = new List<Dictionary<string, object>>(); 
      string publisherid = HttpContext.Current.Session["AccountID"].ToString(); 
      DataTable dt = new DataTable(); 
      if (!string.IsNullOrEmpty(publisherid)) 
      { 
      using (SqlConnection con = new SqlConnection(@"server=203.115.195.52;user Id=appl;password=mcom007;database=mcom_ad_engine")) 
      { 
       //string StartDate = DateTime.Now.AddDays(-180).ToString("yyyy-MM-dd"); 
       string StartDate = DateTime.Now.AddDays(-60).ToString("yyyy-MM-dd"); 
       string EndDate = DateTime.Now.ToString("yyyy-MM-dd"); 
       SqlCommand cmd = new SqlCommand("Sp_publisher_TotalPayout_Report", con); 
       cmd.CommandTimeout = 50; 
       cmd.CommandType = CommandType.StoredProcedure; 
       cmd.Parameters.AddWithValue("@publisherid", publisherid); 
       cmd.Parameters.AddWithValue("@istartdate", StartDate); 
       cmd.Parameters.AddWithValue("@ienddate", EndDate); 
       con.Open(); 
       SqlDataAdapter da = new SqlDataAdapter(cmd); 
       da.Fill(dt); 
       System.Web.Script.Serialization.JavaScriptSerializer serializer = new System.Web.Script.Serialization.JavaScriptSerializer(); 

       Dictionary<string, object> row; 
       foreach (DataRow dr in dt.Rows) 
       { 
        row = new Dictionary<string, object>(); 
        foreach (DataColumn col in dt.Columns) 
        { 
         row.Add(col.ColumnName, dr[col]); 
        } 
        rows.Add(row); 
       } 
      } 
      } 
      else 
      { 
       //Navigate to Login Page 
      } 
      return rows; 
     }