簡體   English   中英

如何使用列表作為一系列圖表元素顯示圖表

[英]how to display chart using a list as a series of an chart elemnt

我已將列表存儲為鍵值對,以便可以將key用作xValue並將Value用作yValues 現在我的問題是:如何在MVC System.Web.Helpers圖表中將此列表用於AddSeries元素?

 double TotalDebts = 300000;

List<KeyValuePair<int, decimal>> dResult = new List<KeyValuePair<int, decimal>>();
List<int> lIndex = dResult.Select(x => x.Key).ToList();
List<decimal> lDepts = dResult.Select(x => x.Value).ToList();

for (int i = 0; i < 250; i++)
{

    if (TotalDebts > 0)
    {

        decimal DebtsLessIncome = Convert.ToDecimal(TotalDebts - 5000);
        decimal InterestCharged = Convert.ToDecimal((DebtsLessIncome * 5) / 100);
        decimal InterestDebt = Convert.ToDecimal(DebtsLessIncome + InterestCharged);
        decimal InterestDebtMLE = Convert.ToDecimal(InterestDebt + 1000);
        TotalDebts = Convert.ToDouble(InterestDebtMLE);

       dResult.Add(new KeyValuePair<int,decimal>());


    }
}

我想在

var key = new Chart(width: 1000, height: 400, theme: Green)
          .AddTitle("Employee Chart")
          .SetXAxis("Total Year", 1)
          .SetYAxis("Money")
          .AddLegend("")

           .AddSeries(
           chartType: "line",
           name: "Current Scenario",
           xValue:lIndex,
           //new[] { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10" },
           yValues:lDepts)
           //new[] { "220000", "200000", "180000", "150000", "120000", "50000", "35000", "25000", "15000", "10000", "0" })

我只是嘗試使用硬編碼值。 它工作正常,但我不知道如何將列表組裝為xValueyValues

我以前沒有在MVC中使用圖表,但是如果您更改以下內容,請閱讀您提供的代碼示例,它將起作用:

List<int> lIndex = dResult.Select(x => x.Key).ToList();
List<decimal> lDepts = dResult.Select(x => x.Value).ToList();

成為string數組:

string[] lIndex = dResult.Select(x => x.Key.ToString()).ToArray();
string[] lDepts = dResult.Select(x => x.Value.ToString()).ToArray();

...

對於圖表,我更喜歡從服務器端返回JSON結果,並使用許多出色的JavaScript圖表庫之一進行呈現。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM