/// <summary>
/// 图表数据配置类
/// </summary>
public class EchartOption
{
public EchartOption()
{
this.xAxis = new List<string>();
this.yAxis1 = new List<decimal>();
this.yAxis2 = new List<decimal>();
this.yAxis3 = new List<decimal>();
this.yAxis4 = new List<decimal>();
this.yAxis = new List<List<decimal>>();
this.valueNames = new List<ValueNameClass>();
}
//适用柱图、折线图
public List<string> xAxis { get; set; }//横轴
public List<decimal> yAxis1 { get; set; }//纵轴1
public List<decimal> yAxis2 { get; set; }//纵轴2
public List<decimal> yAxis3 { get; set; }//纵轴3
public List<decimal> yAxis4 { get; set; }//纵轴4
public List<List<decimal>> yAxis { get; set; }//多柱图集合
//适用饼图
public List<ValueNameClass> valueNames { get; set; }
public List<string> legend { get; set; }
}
/// <summary>
/// 图表数据配置类
/// </summary>
public class ValueNameClass
{
public object value { get; set; }
public string name { get; set; }
}
/// <summary>
/// 静态数据类
/// </summary>
public static class StaticDataClass {
public static List<string> QuarterList { get; set; } = new List<string> { "第一季度", "第二季度", "第三季度", "第四季度" };
}
public class EchartDataModel{
public string Year {get;set;}
public decimal Value {get;set;}
}
EchartOption echartData = new EchartOption();//
List<EchartDataModel> dataList = new List<EchartDataModel>(){
new EchartDataModel(){Year="2024",Value=20.8},
new EchartDataModel(){Year="2025",Value=21.8},
}
foreach (var item in dataList)
{
echartData.xAxis.Add(item.Year + "年");
echartData.yAxis1.Add(item.Value);
}