-2

我想在不使用脚本代码的情况下从 json 文件中获取数据!

我正在使用 MVC4 并想将代码放在 .cshtml 文件中,我该怎么做?

(我正在使用剑道功能)

例子:

@{
    ViewBag.Title = "Home Page";
}

<div class="chart-wrapper">
    @(Html.Kendo().Chart()
        .Name("chart")
                .Title(title => title
                    .Text("Share of Internet Population Growth, 2007 - 2012")
                    .Position(ChartTitlePosition.Bottom))
        .Legend(legend => legend
            .Visible(false)
        )
        .DataSource(dataSource=>dataSource.Read(read=>read.Url("~/")))      

        .Events(e => e.SeriesClick("onSeriesHover"))
        .Series(series => {
            series.Pie(new dynamic[] {
                new {category="Asia",value=53.8,color="#9de219"},
                new {category="Europe",value=16.1,color="#90cc38"},
                new {category="LatinAmerica",value=11.3,color="#068c35"},
                new {category="Africa",value=9.6,color="#006634"},
                new {category="MiddleEast",value=5.2,color="#004d38"},
                new {category="NorthAmerica",value=3.6,color="#033939"}           
            })
            .Labels(labels => labels
                .Template("#= category #: #= value#%")
                .Background("transparent")
                .Visible(true)
                .Color("Red")
            )
            .StartAngle(150);
        })
        .Tooltip(tooltip => tooltip
            .Visible(true)
            .Format("{0}%")
        )

    ) 
    <script>
        function onSeriesClick(e) {
            alert(kendo.format("Series click :: {0} ({1}): {2}",
                e.series.name, e.category, e.value));
        }


    </script>
</div>

我已经使用 .DataSource(dataSource=>dataSource.Read(read=>read.Url("~/"))) 但不工作

4

1 回答 1

0

像这样试试

例子

看法

  @(Html.Kendo().Chart<Model.DashboardPieChartModel>()
            .Name("PieChartPopup")
                    .Events(events => events.DataBound("onDataBound"))
          .Legend(legend => legend
            .Visible(false)
        )
            .DataSource(ds =>
            {
                ds.Read(read => read.Action("Read_PieChart", "Dashboard"));
            }
            )

            .Series(series =>
            {
                series.Pie(
                    model => model.Percentage,
                    model => model.Service, null, null
                ).Labels(labels => labels
            .Visible(true)
            .Template("${ category } - ${ value }%")

            ).Overlay(ChartPieSeriesOverlay.None);
            })

            .Tooltip(tooltip => tooltip
            .Visible(true)
            .Template("${ category } - ${ value }%")
            )

        )

控制器

public JsonResult Read_PieChart()
        {

           //Whatever you do here


            return Json(return your data);
        }

阅读此链接:http ://demos.kendoui.c​​om/dataviz/pie-charts/remote-data.html

于 2013-09-04T09:40:03.047 回答