如何使用asp.net中的DotNet.Highcharts从数据库绑定highcharts

时间:2017-03-16 08:32:07

标签: asp.net asp.net-charts

如何获取此数据" {29.9,71.5,106.4}"来自数据库???

DotNet.Highcharts.Highcharts chart = new DotNet.Highcharts.Highcharts("chart")
.InitChart(new Chart { Type = ChartTypes.Bar })
.SetTitle(new Title { Text = "Wind speed during two days" })
.SetLegend(new Legend { Enabled = false })
.SetXAxis(new XAxis{
Categories = new[] { "Jan", "Feb", "Mar" }
 }).SetSeries(new Series{
Data = new Data(new object[] { 29.9, 71.5, 106.4})
 });
ltrChart.Text = chart.ToHtmlString();

1 个答案:

答案 0 :(得分:0)

我使用此代码及其工作.....

DataTable dt2 = new DataTable();
dt2 = Chart_BL.fetch_Chart_Data(1);

decimal[] ar1 = new decimal[dt2.Rows.Count];

for (int i = 0; i < dt2.Rows.Count; i++)
    {
      ar1[i] = Convert.ToDecimal(dt2.Rows[i]["age"].ToString());

    }

DotNet.Highcharts.Highcharts chart2 = new DotNet.Highcharts.Highcharts("chart_2")
               .InitChart(new Chart { Type = ChartTypes.Bar })
               .SetTitle(new Title { Text = "" })
               .SetLegend(new Legend { Enabled = true })
               .SetXAxis(new XAxis
               {
                   Categories = new String[] { "10th", "11th", "10th", "11th" }
               })
                .SetSeries(new Series
                {
                    Data = new Data(ar1.Select(x => (object)x).ToArray())

                });

enter image description here