【问题标题】:Piechart is not working in PartialView饼图在局部视图中不起作用
【发布时间】:2018-06-27 11:04:56
【问题描述】:

通常应用程序与 ViewBag 一起使用。但是当我使用局部视图时,它不能使用 viewbag。所以我把它作为一个字符串扔掉。数据正在传输,但饼图不打印。

部分视图中的 JavaScript

@model 字符串

    window.onload = function () {

        var chart = new CanvasJS.Chart("chartContainer", {
            theme: "light1", // "light1", "light2", "dark1", "dark2"
            exportEnabled: true,
            animationEnabled: true,
            title: {
                text: "Indian Smartphone Market Share"
            },
            subtitles: [{
                text: "Q2, 2016"
            }],
            data: [{
                type: "pie",
                startAngle: 180,
                toolTipContent: "<b>{label}</b>: {y}%",
                showInLegend: "true",
                legendText: "{label}",
                indexLabel: "{label} - {y}%",
                dataPoints: @Html.Raw(Model),
            }]
        });
        chart.render();

    }
</script>

控制器

 [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);
    }

【问题讨论】:

    标签: javascript model-view-controller partial-views pie-chart


    【解决方案1】:

    我是这样解决的:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-03-03
      • 2013-02-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多