C# 仪表板的背景图表。NETMVC内核

C# 仪表板的背景图表。NETMVC内核,c#,asp.net-mvc,C#,Asp.net Mvc,我试着做一个仪表板, 我希望每个部分的颜色都能自动定义。我怎么能做到? 谢谢您谢谢您的回复:这是一个控制器: 公共异步任务GetPiePercentage(字符串参数) { var参数=JsonConvert.DeserializeObject(param); var cgList=Json(等待GetGeneralConditionsPercentage(参数)); 返回Json(新的{Cg=cgList}); } 公共异步任务GetGeneralConditionsPercentage(字典

我试着做一个仪表板, 我希望每个部分的颜色都能自动定义。我怎么能做到? 谢谢您

谢谢您的回复:这是一个控制器:
公共异步任务GetPiePercentage(字符串参数)
{
var参数=JsonConvert.DeserializeObject(param);
var cgList=Json(等待GetGeneralConditionsPercentage(参数));
返回Json(新的{Cg=cgList});
}
公共异步任务GetGeneralConditionsPercentage(字典参数){
仪表板GeneralConditionViewModel listGC=新仪表板GeneralConditionViewModel();
var tmp=等待GetProjectsByRole(c=>c.一般条件,参数);
listGC.Percentages=tmp.Percentages;
listGC.ProjectGroups=tmp.ProjectGroups;
listGC.BackGroundColors=tmp.BackGroundColors;
var projectGroups=listGC.projectGroups;
var sum=projectGroups.sum(item=>item.Count);
listGC.Percentages=projectGroups.ConvertAll(x=>Math.Round((x.Count*100),2,middpointrounding.AwayFromZero)/sum);
listGC.GeneralConditions=projectGroups.Select(x=>x.Filter.ToList();
var counttype=listGC.GeneralConditions.Count();
listGC.BackGroundColors=setColorsList(counttype);
返回listGC;
} 
私有列表setColorsList(int filterNum){
列表颜色=新列表(){“#000066”、“#006600”、“#ffff00”、“#ff0000”、“#000099”、“#00cc00”、“#cc9900”、“#ff0066”、“#00ccff”、“66ff99”、“#663300”、“#993333”};
List tmpColors=新列表();
对于(int i=0;i
js:

$(文档).ready(函数(){
ajaxForDashboard(空);
});
功能ajaxForDashboard(参数){
$.ajax({
键入:“获取”,
//url:'@url.Action(“GettyPoologyPercentage”,“DashBoard”),
url:“/Dashboard/GetPiePercentage”,
contentType:“应用程序/json;字符集=utf-8”,
数据:{'param':JSON.stringify(参数)},
//数据:{'param':参数},
数据类型:“json”,
成功:功能(结果){
var res=JSON.stringify(结果);
var array=JSON.parse(res);
var arraypetype=array.type.value;
var arrayPieCG=array.cg.value;
var arrayStage=array.stage.value;
fillPieChart(ArrayType.Typeologys、ArrayType.Percentage、ArrayType.BackgroundColor、“myPieChartType”);
fillPieChart(arrayPieCG.generalConditions,arrayPieCG.Percentage,arrayPieCG.BackgroundColor,“myPieChartCG”);
控制台日志(arrayStage);
var节点=document.createElement(“div”);
document.getElementById(“cardBodyType”).appendChild(节点);
document.getElementById(“cardBodyType”).getElementsByTagName(“div”)[1]。innerHTML=(setBodyCard(arrayTypeType.typologies,arrayTypeType.BackgroundColor));
node2=document.createElement(“div”);
document.getElementById(“cardBodyCG”).appendChild(node2);
document.getElementById(“cardBodyCG”).getElementsByTagName(“div”)[1]。innerHTML=(setBodyCard(arrayPieCG.generalConditions,arrayPieCG.backgroundColor));
设置可调(arrayStage);
}
});
}
//其他职能
函数填充图(标签、数据、BG颜色、div){
Chart.defaults.global.defaultFontFamily='Nunito','-苹果系统,系统用户界面,BlinkMacSystemFont,“Segoe用户界面”,Roboto,“Helvetica Neue”,Arial,无衬线字体';
Chart.defaults.global.defaultFontColor='#858796';
//饼图示例
var ctx=document.getElementById(div);
var myPieChart=新图表(ctx{
键入:“甜甜圈”,
数据:{
标签:标签,
数据集:[{
数据:数据,
背景颜色:背景颜色,
hoverBackgroundColor:bgColors,
hoverBorderColor:“rgba(234236244,1)”,
}],
},
选项:{
MaintaintAspectRatio:false,
工具提示:{
背景颜色:“rgb(255255)”,
bodyFontColor:#858796“,
边框颜色:“#dddfeb”,
边框宽度:1,
加上:15,
加上:15,
显示颜色:假,
护理添加:10,
},
图例:{
显示:假
},
门诊量:80,
},
});
}
函数setBodyCard(过滤器、颜色){
var contentHtml=“”;
对于(变量i=0;i-1){
trNUmber[j].innerHTML=list[i].count;
trPercentage[j].innerHTML=percentage[i]+“%”;
打破
}
}       
}
document.getElementById(“number”).value=trNUmber.innerHTML;
document.getElementById(“percentage”).value=trPercentage.innerHTML;

}
如果不显示代码,我们将无法提供帮助:请尝试更明确一些?您是否使用特定的库?嗨,欢迎使用StackOverflow。为了帮助我们给你最好的建议,我们倾向于询问问题的答案
            Thank you for your responses: this is a controller:

                public async Task<JsonResult> GetPiePercentage(string param)
                {

                    var parameters = JsonConvert.DeserializeObject<Dictionary<string, object>> (param);

                    var cgList = Json(await GetGeneralConditionsPercentage(parameters));

                    return Json(new { Cg = cgList});

                }
public async Task GetGeneralConditionsPercentage(Dictionary param) { 
    DashBoardGeneralConditionViewModel listGC = new DashBoardGeneralConditionViewModel();
             var tmp = await GetProjectsByRole(c => c.GeneralCondition,param); 
             listGC.Percentages = tmp.Percentages;
         listGC.ProjectGroups = tmp.ProjectGroups; 
        listGC.BackGroundColors = tmp.BackGroundColors;
         var projectGroups = listGC.ProjectGroups; 
        var sum = projectGroups.Sum(item => item.Count);
listGC.Percentages = projectGroups.ConvertAll(x => Math.Round((x.Count * 100), 2, MidpointRounding.AwayFromZero) / sum); 
        listGC.GeneralConditions = projectGroups.Select(x => x.Filter).ToList();
         var counttype = listGC.GeneralConditions.Count(); 
        listGC.BackGroundColors = setColorsList(counttype);
         return listGC; 
        } 
        private List setColorsList(int filterNum) { 
        List Colors = new List() { "#000066", "#006600", "#ffff00", "#ff0000", "#000099", "#00cc00", "#cc9900", "#ff0066", "#00ccff", "66ff99", "#663300", "#993333" };
         List tmpColors = new List();
         for (int i = 0; i < filterNum; i++) 
        { 
        tmpColors.Add(Colors[i]); 
        } 
        return tmpColors;
         }