2012-01-09 63 views
1

名單我想創建與ASP主要概述圖表:圖表控件,像這樣:創建多列系列ASP:圖表與自定義對象在asp.net C#

enter image description here

而是安德魯,等等這將是會計年度(2009年,2010年,2011年等),產品將是4種類型的成本。 但是我怎麼做到這一點與被contstructed像這樣的自定義對象的列表:

名單< Cost_cost> listOfCosts

  • 成本

    • 類型(可以是四種類型中的一種)
    • 金額(浮點)
    • 會計年度

有人得到一個鏈接或提示如何處理?

+0

嚴重的是,沒有人?甚至沒有鏈接到嘖嘖? – 2012-01-10 22:39:49

回答

1

找到了一個解決方案,它部分是硬編碼的,即成本類型,但由於需要在後天上傳,它會這樣做。

當然,下面的代碼是我創建Chart1的mainlegend和地區以及一些造型的東西后:

//Set the amount of the four series to zero 
float totalAmountHousing = 0, totalAmountPersonnel = 0, totalAmountServices = 0, totalAmountIT = 0; 

//Create the four series per year 
Series sr = new Series(); Series sr2 = new Series(); Series sr3 = new Series(); Series sr4 = new Series(); 

//Set the series to the same chart area 
sr.ChartArea = "mainArea"; sr2.ChartArea = "mainArea"; sr3.ChartArea = "mainArea"; sr4.ChartArea = "mainArea"; 

//Set them to the same legend 
sr.Legend = "mainLegend"; sr2.Legend = "mainLegend"; sr3.Legend = "mainLegend"; sr4.Legend = "mainLegend"; 

//Set the names of the 4 series 
sr.Name = "Housing"; sr2.Name = "IT"; sr3.Name = "Services"; sr4.Name = "Personnel"; 

//Add the series to the chart 
Chart1.Series.Add(sr); Chart1.Series.Add(sr2); Chart1.Series.Add(sr3); Chart1.Series.Add(sr4); 

//Set drawing style to cylinder of the four costs 
Chart1.Series["Housing"]["DrawingStyle"] = "Cylinder"; 
Chart1.Series["IT"]["DrawingStyle"] = "Cylinder"; 
Chart1.Series["Services"]["DrawingStyle"] = "Cylinder"; 
Chart1.Series["Personnel"]["DrawingStyle"] = "Cylinder"; 

for (int i = 0; i < listOfFiscalYears.Count; i++) { 

    //generate some point for the chart 
    for (int j = 0; j < listOfCosts.Count; j++) { 
     if ((listOfCosts[j].Type).ToLower() == "housing" && listOfCosts[j].Cost_fiscalYear.Year == int.Parse(listOfFiscalYears[i].ToString())) totalAmountHousing += (float)listOfCosts[j].Amount; 
     if ((listOfCosts[j].Type).ToLower() == "it"   && listOfCosts[j].Cost_fiscalYear.Year == int.Parse(listOfFiscalYears[i].ToString())) totalAmountIT += (float)listOfCosts[j].Amount; 
     if ((listOfCosts[j].Type).ToLower() == "services" && listOfCosts[j].Cost_fiscalYear.Year == int.Parse(listOfFiscalYears[i].ToString())) totalAmountServices += (float)listOfCosts[j].Amount; 
     if ((listOfCosts[j].Type).ToLower() == "personnel" && listOfCosts[j].Cost_fiscalYear.Year == int.Parse(listOfFiscalYears[i].ToString())) totalAmountPersonnel += (float)listOfCosts[j].Amount; 
    } 

    Chart1.Series["Housing"].Points.Add(totalAmountHousing); 
    Chart1.Series["IT"].Points.Add(totalAmountIT); 
    Chart1.Series["Services"].Points.Add(totalAmountServices); 
    Chart1.Series["Personnel"].Points.Add(totalAmountPersonnel); 
    Chart1.ChartAreas["mainArea"].AxisX.Interval = 1; 

    //Add custom label to the X axis 
    Chart1.ChartAreas[0].AxisX.CustomLabels.Add(new CustomLabel(i, i + 2, (listOfFiscalYears[i].ToString()), 0, LabelMarkStyle.None)); 

    //Reset the total cost after they have been added for the year 
    totalAmountHousing = 0; totalAmountPersonnel = 0; totalAmountServices = 0; totalAmountIT = 0; 
}