Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/413.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Piechart不在PartialView中工作_Javascript_Model View Controller_Partial Views_Pie Chart - Fatal编程技术网

Javascript Piechart不在PartialView中工作

Javascript Piechart不在PartialView中工作,javascript,model-view-controller,partial-views,pie-chart,Javascript,Model View Controller,Partial Views,Pie Chart,通常,应用程序正在使用ViewBag。但是当我使用部分视图时,它不能使用viewbag。所以我把它当作绳子扔了。数据正在运行,但图表不打印 PartialView中的Javascript @模型串 window.onload=函数(){ var chart=new CanvasJS.chart(“chartContainer”{ 主题:“light1”、“light1”、“light2”、“dark1”、“dark2” exportEnabled:true, animationEnabled:

通常,应用程序正在使用ViewBag。但是当我使用部分视图时,它不能使用viewbag。所以我把它当作绳子扔了。数据正在运行,但图表不打印

PartialView中的Javascript

@模型串

window.onload=函数(){
var chart=new CanvasJS.chart(“chartContainer”{
主题:“light1”、“light1”、“light2”、“dark1”、“dark2”
exportEnabled:true,
animationEnabled:没错,
标题:{
文字:“印度智能手机市场份额”
},
字幕:[{
正文:“2016年第二季度”
}],
数据:[{
键入:“馅饼”,
startAngle:180,
toolTipContent:“{label}:{y}%”,
showInLegend:“正确”,
legendText:“{label}”,
索引标签:“{label}-{y}%”,
数据点:@Html.Raw(模型),
}]
});
chart.render();
}
控制器

 [HttpPost]
    public ActionResult Index(List<string> ulkeler)
    {
        NwContext db = new NwContext();
        List<Ulke> ulkecs = new List<Ulke>();
        foreach (var item in ulkeler)
        {
           ulkecs.Add( new Ulke { count = db.Customers.Where(x => x.Country == item).Count(),name =item });
        }

        List<DataPoint> dataPoints = new List<DataPoint>();
        foreach (var item in ulkecs)
        {

            dataPoints.Add(new DataPoint(item.name.ToString(), Convert.ToInt32(item.count)));

        }

        string a= JsonConvert.SerializeObject(dataPoints);
        return PartialView("PartialViewExample", a);
    }
[HttpPost]
公共行动结果索引(列表ulkeler)
{
NwContext db=新的NwContext();
List ulkecs=新列表();
foreach(ulkeler中的var项目)
{
Add(新的Ulke{count=db.Customers.Where(x=>x.Country==item.count(),name=item});
}
列表数据点=新列表();
foreach(ulkecs中的var项目)
{
添加(新的数据点(item.name.ToString(),Convert.ToInt32(item.count));
}
字符串a=JsonConvert.SerializeObject(数据点);
返回PartialView(“PartialView示例”,a);
}
我这样修复:

我删除了这个
window.onload=function(){
,写了
function show(){

<button onclick="show()"></button>

<button onclick="show()"></button>