有谁能告诉我如何将Arraylist与dotnet高图绑定,以便我可以使用SQL Server数据创建高图表?
我设法将数据从SQL Server复制到下面的数组列表是代码
using (SqlConnection cnn = new SqlConnection("Data Source=INBDQ2WK2LBCD2S\\SQLEXPRESS;Initial Catalog=MCAS;Integrated Security=SSPI"))
{
SqlDataAdapter da = new SqlDataAdapter("select top(100) * from Test4 order by Id desc", cnn);
DataSet ds = new DataSet();
da.Fill(ds, "Test4");
List<string> xValues = new List<string>();
foreach (DataRow row in ds.Tables["Test4"].Rows)
{
xValues.Add(row["x"].ToString());
}
Response.Write(xValues);
现在我要创建高级图表。如何将此arraylist与highchart绑定?
答案 0 :(得分:0)
DotNetHighCharts在为图表制作系列时使用object []。
e.g。新系列{数据=新数据(对象[] {1,2,3,4,5}}
也许将其设为List<object>
而不是List<string>
In code behind:
List<object> values_List = new List<object>();
object[] values = values_List.ToArray();
Highcharts chart1 = new Highcharts("Chart1")
.InitChart(new Chart { Height = 300, Width = 400, Type = ChartTypes.Column })
.SetSeries(new Series { Data = new Data(values)});
ltrChart1.Text = chart1.ToHtmlString();
In aspx:
<asp:Literal ID="ltrChart1" runat="server"></asp:Literal>