[英]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" })
我只是尝试使用硬编码值。 它工作正常,但我不知道如何将列表组装为xValue
和yValues
。
我以前没有在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.