1
試圖建立在asp.net的AJAX線圖時,我有一些問題。我想要做的是從下拉列表中選擇一個類別,然後折線圖將顯示每個類別每個月發出的產品總和。這是在表示層代碼:AJAX折線圖中Asp.Net
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
我不知道如何根據我的情況解決這個問題。提前致謝。
謝謝!有用!!!但是你有沒有關於如何從代碼後面更改線條顏色的想法? –
對不起,我從來沒有使用AJAX線圖前,而是在此基礎上:http://www.asp.net/AjaxLibrary/AjaxControlToolkitSampleSite/LineChart/LineChart.aspx,控制具有'BaseLineColor'財產,也許這就是它? – ekad