Highcharts不同的数据相同的图表

时间:2018-04-30 22:16:50

标签: javascript java charts highcharts

我想知道如何将比较数据添加到同一个图表,我有当前的连接代码,以及下面的HTML,我想在同一个图表上比较Rainfall和Sunlight Data,它们都来自同一张表。我是否需要创建另一个get set?............................

public string chartData
{
    get;
    set;
}
 public void renderChart()  
{  
   DataTable dt = GetData(); 
   data as datatable   
   List<int> _data = new List<int>();   
   foreach (DataRow row in dt.Rows)   
   {   
        _data.Add((int)row["Rainfall"]);

   }  
   JavaScriptSerializer jss = new JavaScriptSerializer();   
  chartData = jss.Serialize(_data);
}



public DataTable GetData()
{
  string connectionString = ConfigurationManager.ConnectionStrings["HighChartsConnectionString"].ConnectionString;
  DataTable dt = new DataTable();

  using (SqlConnection connection = new SqlConnection("SQLServerConnection"))
  {
    using (SqlCommand command = new SqlCommand("Select Rainfall,Sunlight from SalesData", connection))
    {
      connection.Open();
      using (SqlDataReader dr = command.ExecuteReader())
      {
        if (dr.HasRows)
        {
          dt.Load(dr);
        }
      }
    }
  }

  return dt;
}
$(function () {  
  $('#container').highcharts({  
    chart: {  
        type: 'column'  
    },  
    title: {  
      text: 'RainFall'  
    },  
    subtitle: {  
      text: ' '  
    },  
    xAxis: {  
      categories: [  
       'Amazon',
       'Sudan',
       'Europe' 
      ]  
    },  
    yAxis: {  
      min: 0,  
      title: {  
        text: 'Rainfall in inches'  
      }  
    },  
    tooltip: {  
      headerFormat: '<span style="font-size:10px">{point.key}</span><table>',  
      pointFormat: '<tr><td style="color:{series.color};padding:0">{series.name}: </td>' +  
        '<td style="padding:0"><b>{point.y:.0f}</b></td></tr>',  
      footerFormat: '</table>',  
      shared: true,  
      useHTML: true  
    },  
    plotOptions: {  
      column: {  
        pointPadding: 0.2,  
        borderWidth: 0  
      }  
    },  
    series: [{
        name: 'RainFall',
        data: <%= chartData%>,
    }]





  });  
});  

1 个答案:

答案 0 :(得分:1)

听起来你需要add another data set to series