0

我想使用基于 ajax 的图表控件制作图表。我已经为它添加了 ajax 工具包。

我想创建如下链接中的图表

http://www.asp.net/ajaxLibrary/AjaxControlToolkitSampleSite/BarChart/BarChart.aspx

通过使用静态数据。我可以创建如下图表

<asp:BarChart ID="BarChart1" runat="server" 
ChartHeight="300" ChartWidth="450" ChartType="StackedColumn"
ChartTitle="United States versus European Widget Production" 
CategoriesAxis="2007,2008,2009,2010,2011,2012"  
ChartTitleColor="blue" CategoryAxisLineColor="Red" 
ValueAxisLineColor="yellow" BaseLineColor="green" >
<Series>
    <asp:BarChartSeries Name="United States" BarColor="#6C1E83" 
    Data="110, 189, 255, 95, 107, 140" />
    <asp:BarChartSeries Name="Europe" BarColor="#D08AD9" 
    Data="49, 77, 95, 68, 70, 79" />
</Series>
</asp:BarChart>

但我不知道如何将现有数据绑定到图表控件的数据源。那么该怎么做呢?

4

2 回答 2

0
private void getData()
    {
        SqlCeConnection conn = new SqlCeConnection("data source='c:\\northwind.sdf';  mode=Exclusive;");
        SqlCeDataAdapter da = new SqlCeDataAdapter("Select [Statistics] from Products",  conn);
        DataTable dtSource = new DataTable();
        da.Fill(dtSource);
        DataRow[] dr = new DataRow[dtSource.Rows.Count];
        dtSource.Rows.CopyTo(dr, 0);
        int[] dblstat= Array.ConvertAll(dr, new Converter<DataRow , int>       (DataRowToint));

    }


    public static int32 DataRowToint(DataRow dr)
    {
        return Convert.ToInt32(dr["Statistics"].ToString());

}

上面的代码将为您提供 int 值数组,将其分配给代码隐藏中的条形图数据。

于 2013-01-28T13:10:03.900 回答
0

这是一个可行的解决方案,只需将数据填充到数据表中,然后像下面一样创建一个十进制数组,分配它..

 protected void Page_Load(object sender, EventArgs e)
    {
        decimal[] usstat = new decimal[] { 10, 15, 16, 18, 20 };
        decimal[] ukstat = new decimal[] { 14, 18, 6, 11, 32 };


        if (BarChart1.Series[0].Name == "US")
        {
            BarChart1.Series[0].BarColor = "#6C1E83";
            BarChart1.Series[0].Data = usstat;
        }


        if (BarChart1.Series[1].Name == "UK")
        {

            BarChart1.Series[1].BarColor = "#D08AD9";
            BarChart1.Series[1].Data = ukstat;
        }

---在.aspx ....

    <asp:BarChart ID="BarChart1" runat="server" ChartHeight="300" ChartWidth="450"  ChartType="StackedColumn" ChartTitle="United States versus European Widget Production"  CategoriesAxis="2007,2008,2009,2010,2011,2012" ChartTitleColor="blue"  CategoryAxisLineColor="Red" ValueAxisLineColor="yellow" BaseLineColor="green" >
<Series>
  <asp:BarChartSeries Name="US"/>
  <asp:BarChartSeries Name="UK"/>
</Series>

于 2013-01-29T07:12:47.710 回答