Asp.Net 中的 AJAX 折线图



我在尝试在 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);

线。错误消息是"无法隐式将十进制类型转换为十进制 []。我从这个网站参考: 折线图 在 Asp.Net

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

获取catSumList后移动totalQuantity声明并将其更改为:

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

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

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

相关内容

  • 没有找到相关文章

最新更新