javascript - Highcharts 子弹图错误 #13

标签 javascript jquery html highcharts

我试图在我的页面中使用项目符号图,但出现错误“Highcharts Error #13”,我在这里找到了解决方案,但它根本没有帮助我。

我从 fiddle 中获取了这段代码,只是想将其插入到我的代码中。这段代码在 fiddle 中工作正常,但在我在控制台中发现错误后,我将其移至 plunker 中,但没有任何反应,控制台中也出现同样的问题。

有人可以帮我定义一下我做错了什么吗?

这是我的js文件:

//-------------------------------------------------------
Highcharts.Renderer.prototype.symbols.line = function(x, y, width, height) {
    return ['M',x ,y + width / 2,'L',x+height,y + width / 2];
};
//-------------------------------------------------------
Highcharts.setOptions({
    chart:{
        type:'bar',
        margin:[5,15,10,100],
    },
    credits:{enabled:false},
    exporting:{enabled:false},
    legend:{enabled:false},
    title:{text:''},
    xAxis:{
        tickLength:0,
        lineColor:'#999',
        lineWidth:1,
        labels:{style:{fontWeight:'bold'}}
    },
    yAxis:{
        min:0,
        minPadding:0,
        maxPadding:0,
        tickColor:'#ccc',
        tickWidth:1,
        tickLength:3,
        gridLineWidth:0,
        endOnTick:true,
        title:{text: ''},
        labels:{
            y:10,
            style:{
                fontSize:'8px'
            },
            formatter:function(){
                if (this.isLast){
                    return this.value + ' %';
                }
                else{
                    return this.value;
                }
            }
        }
    },
    tooltip:{
        enabled:true,
        backgroundColor:'rgba(255, 255, 255, .85)',
        borderWidth:0,
        shadow:true,
        style:{fontSize:'10px',padding:8},
        formatter:function() {
            return this.series.name + ": <strong>" + Highcharts.numberFormat(this.y,2) + "</strong>";
        }
    },
    plotOptions:{
        bar:{
            color:'#000',
            shadow:false,
            borderWidth:0,
        },
        scatter:{
            marker:{
                symbol:'line',
                lineWidth:3,
                radius:8,
                lineColor:'#000'
            }
        }
    }
});
//-------------------------------------------------------
$(document).ready(function() {

var chart1 = new Highcharts.Chart({
    chart:{renderTo:'container'},
    xAxis:{categories:['bar']},
    yAxis:{
        max:100,
        labels:{y:10,style:{fontSize:'8px'}},
        plotBands:[{from:0,to:70,color: 'rgba(103,103,103,.35)'},
            {from:70,to:85,color: 'rgba(153,153,153,.35)'},
            {from:85,to:100,color: 'rgba(204,204,204,.35)'}]
    },
    series:[{name:'Measure',pointWidth:10,data:[80]},
        {name:'Target',type: 'scatter',data:[90],}]
});
}(jQuery));
//-------------------------------------------------------

以及我页面中的这个 div

<div id="container" style="height:36px;width:350px;"></div>

最佳答案

所有代码都应该放在 document.ready 中。

$(document).ready(function() {
//-------------------------------------------------------
Highcharts.Renderer.prototype.symbols.line = function(x, y, width, height) {
  return ['M', x, y + width / 2, 'L', x + height, y + width / 2];
};

修复演示:http://jsfiddle.net/hqykwrjd/1/

关于javascript - Highcharts 子弹图错误 #13,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34189281/

相关文章:

javascript - 有没有办法测试 console.log 条目

javascript - 如何从 foo.onload = function(){ 获得响应?

javascript - 使用 jQuery 动态显示 Django 表单中的选定选项

javascript - 如何洗牌兄弟 div 但保持子元素相同的顺序

javascript - 使用 jQuery 将文本添加到 div

html - 列标题居中对齐,但希望单元格右对齐

javascript - 使用 Twitter Bootstrap 创建合并表格单元格

javascript - 如何在mongodb数据库上存储setTimeout id?

javascript - 防止 iOS WebApp 中的水平滚动

javascript - 如何在 JQuery 中使用 foreach 循环