Highcharts不会在我的MVC4 .NET项目中呈现

时间:2014-12-01 11:27:09

标签: javascript asp.net-mvc-4 highcharts

我正在尝试让Highcharts在我的项目中工作。在Notepad ++中运行代码时,它可以工作,但是当我将相同的代码插入到我的.NET MVC4项目中时,它不会呈现任何内容。

下面是代码:

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
<script src="http://code.highcharts.com/highcharts.js"></script>
<script type="text/javascript">
    $(function () {
        $('#container').highcharts({
            chart: {
                plotBackgroundColor: null,
                plotBorderWidth: 1,//null,
                plotShadow: false
            },
            title: {
                text: 'Browser market shares at a specific website, 2014'
            },
            tooltip: {
                pointFormat: '{series.name}: <b>{point.percentage:.1f}%</b>'
            },
            plotOptions: {
                pie: {
                    allowPointSelect: true,
                    cursor: 'pointer',
                    dataLabels: {
                        enabled: true,
                        format: '<b>{point.name}</b>: {point.percentage:.1f} %',
                        style: {
                            color: (Highcharts.theme && Highcharts.theme.contrastTextColor) || 'black'
                        }
                    }
                }
            },
            series: [{
                type: 'pie',
                name: 'Browser share',
                data: [
                    ['Firefox', 45.0],
                    ['IE', 26.8],
                    {
                        name: 'Chrome',
                        y: 12.8,
                        sliced: true,
                        selected: true
                    },
                    ['Safari', 8.5],
                    ['Opera', 6.2],
                    ['Others', 0.7]
                ]
            }]
        });
    });
</script>

从chrome返回以下错误消息:

Picture of the error message

虽然Firefox说:

TypeError: $(...).highcharts is not a function

任何人都知道为什么它不会渲染?

1 个答案:

答案 0 :(得分:1)

我在这里找到了解决方案:Uncaught TypeError: undefined is not a function - Highcharts - MVC

我更改了以下代码:

 $(function () {
        $('#container').highcharts({
            title: {
                text: 'Monthly Average Temperature',
                x: -20 //center
         },
         // rest of code omitted 

以下内容:

$(function () {
    Chart = new Highcharts.Chart({
        chart: {
            renderTo: 'container'
        },

        title: {
             text: 'Monthly Average Temperature',
             x: -20 //center
         },
         //rest of code omitted

现在它工作正常:)