0

如何将 Telerik ASP.Net MVC 图表(不是 jQuery 版本的 Kendo)绑定到 JSON?例如,我想将下面的图表(注意:该系列暂时用虚拟数据存根,但希望你明白)绑定到一个返回 JSON 的 JavaScript 函数。我很难找到如何使用 Telerik ASP.Net MVC 图表执行此操作的示例。我确实找到了用于 jQuery 图表的 Kendo UI 示例 - 但我没有使用它。

@(Html.Kendo().Chart()
.Name("GallonsPerMonth")
.Title("Total Gallons Per Month")
.Legend(legend => legend
    .Position(ChartLegendPosition.Top)
    .Visible(true)
)
.Theme("Bootstrap")
.ChartArea(chartArea => chartArea
    .Background("transparent")
    .Height(600)
)
.Series(series =>
{
    series.Column(new double[] { 825, 775, 875, 900, 925, 1111, 1200, 1175, 1100, 1000, 875, 800 }).Name("Estimated");
    series.Line(new double[] { 700, 795, 900, 850, 950, 905, 1175, 1100, 1000, 1050, 700, 650 }).Name("Actual").Color("red");

})
.CategoryAxis(axis => axis
    .Name("series-axis")
    .Line(line => line.Visible(false))
)
.CategoryAxis(axis => axis
    .Name("label-axis")
    .Categories("Jan", "Feb", "Mar", "Apr", "May", "Jun", "July", "Aug", "Sep", "Oct", "Nov", "Dec")
)
.ValueAxis(axis => axis//.Logarithmic()
    .Numeric()
    .Labels(labels => labels.Format("{0}"))

    // Move the label-axis all the way down the value axis
    .AxisCrossingValue(0, int.MinValue)
)
.Tooltip(tooltip => tooltip
    .Visible(true)
    .Format("{0}")
    .Template("#= series.name #: #= value #")
)

)

dsd

4

1 回答 1

1

您可以使用没有系列数据的 MVC 帮助程序扩展来创建图表,因此在文档准备好时使用 JavaScript 添加它。

<script>
    $(document).ready(function () {
        $.getJSON('your-url', function (data) {
            var chart = $("#GallonsPerMonth").data("kendoChart");
            var series = chart.options.series;
            // first series
            series[0].data = data;
            chart.redraw();
        });
    }
</script>

注意我正在将数据添加到拳头系列。

于 2018-10-11T15:17:24.557 回答