【问题标题】:AJAX Line Chart in Asp.NetAsp.Net 中的 AJAX 折线图
【发布时间】:2014-01-18 12:01:59
【问题描述】:

尝试在 asp.net 中设置 AJAX 折线图时遇到一些问题。我要做的是从下拉列表中选择一个类别,然后折线图将显示每个类别每月发送的产品总和。这是表示层的代码:

protected void ddlCategory_SelectedIndexChanged(object sender, EventArgs e)
{
    string categoryName = ddlCategory.SelectedItem.ToString();
    string deliveryDate = "";
    decimal[] totalQuantity;

    List<ProductPacking> catSumList = new List<ProductPacking>();
    for (int count = 0; count < catSumList.Count; count++)
    {
        deliveryDate = catSumList[count].deliveryDate;
        totalQuantity = Convert.ToDecimal(catSumList[count].productQuantity);
    }
    lcCategory.Series.Add(new AjaxControlToolkit.LineChartSeries { Data = totalQuantity });
    lcCategory.CategoriesAxis = string.Join(",", deliveryDate);
    lcCategory.ChartTitle = string.Format("", deliveryDate);
    lcCategory.Visible = true;
}

以及业务逻辑层中的代码:

public List<ProductPacking> getSumCategoryByMonth(string categoryName)
{
    List<ProductPacking> ft = new List<ProductPacking>();
    ft = prodPack.getSumCategoryByMonth(categoryName);
    return ft;
}

以及数据访问层中的代码:

public List<ProductPacking> getSumCategoryByMonth(string categoryName)
{
    List<ProductPacking> ft = new List<ProductPacking>();

    using (var connection = new SqlConnection(FoodBankDB.connectionString))
    {
        SqlCommand command = new SqlCommand("SELECT SUM(Convert(INT, ddi.productQuantity)) AS totalQuantity, pc.categoryName, d.deliveryDate FROM dbo.DistributionDistributedItems ddi " +
            " INNER JOIN dbo.ProductVariants pv ON ddi.productVariant = pv.id " +
            " INNER JOIN dbo.Products p ON pv.product = p.id " +
            " INNER JOIN dbo.ProductCategories pc ON p.productCategory = pc.id " +
            " INNER JOIN dbo.Distributions d ON ddi.distribution = d.id " +
            " WHERE categoryName = '" + categoryName + "'" + 
            " GROUP BY pc.categoryName, d.deliveryDate", connection);
        connection.Open();
        using (var dr = command.ExecuteReader())
        {
            while (dr.Read())
            {
                ft.Add(new ProductPacking(Convert.ToInt32(dr["totalQuantity"].ToString()), dr["deliveryDate"].ToString()));
            }
        }
    }
    return ft;
}

但是,在表示层周围有一个错误

totalQuantity = Convert.ToDecimal(catSumList[count].productQuantity);

线。错误消息是无法将类型小数隐式转换为小数 []。我从这个网站提到:Line Chart In Asp.Net

我想知道如何根据我的情况解决这个问题。提前致谢。

【问题讨论】:

    标签: c# asp.net ajax linechart


    【解决方案1】:

    在你得到catSumList之后移动totalQuantity的声明,改成这样:

    List<ProductPacking> catSumList = new List<ProductPacking>();
    catSumList = BLL.getSumCategoryByMonth("Some Category");
    decimal[] totalQuantity = new decimal[catSumList.Count];
    

    然后使用count 作为for 块中的索引输入totalQuantity 的值:

    for (int count = 0; count < catSumList.Count; count++)
    {
        deliveryDate = catSumList[count].deliveryDate;
        totalQuantity[count] = Convert.ToDecimal(catSumList[count].productQuantity);
    }
    

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-03-07
    • 1970-01-01
    • 2015-12-05
    • 2021-10-31
    • 1970-01-01
    相关资源
    最近更新 更多