Highcharts 图表标题在图表上重叠

Highcharts 图表标题在图表上重叠,highcharts,Highcharts,我试图把标题放在图表上,但当我添加标题时,它本身就是重叠的图表。 这是JSFIDLE代码。你们知道我需要设置什么属性才能让它工作吗 //------------------------------------------------------- Highcharts.Renderer.prototype.symbols.line = function(x, y, width, height) { return ['M',x ,y + width / 2,'L',x+height,y +

我试图把标题放在图表上,但当我添加标题时,它本身就是重叠的图表。 这是JSFIDLE代码。你们知道我需要设置什么属性才能让它工作吗

//-------------------------------------------------------
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:{
        defaultSeriesType:'bar',
        marginTop:5,
        marginRight:15,
        marginBottom:10,
        marginLeft:100,        
        borderWidth:0
    },
    credits:{enabled:false},
    exporting:{enabled:false},
    title:{text:'Title'},
    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;
                }
            },
            enabled: false
        }
    },
    legend:{enabled:false},
    tooltip:{
        enabled:true,
        backgroundColor:'rgba(255, 255, 255, .85)',
        borderWidth:0,
        shadow:true,
        style:{fontSize:'10px',padding:2},
        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:'#f00'
            }
        }
    }
});

//-------------------------------------------------------
var chart1 = new Highcharts.Chart({
    chart:{renderTo:'container1'},
    xAxis:{categories:['Title 1']},
    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],}]
});
//-------------------------------------------------------
Highcharts.Renderer.prototype.symbols.line=函数(x、y、宽度、高度){
返回['M',x,y+宽度/2,'L',x+高度,y+宽度/2];
};
//-------------------------------------------------------
Highcharts.setOptions({
图表:{
defaultSeriesType:'bar',
玛金托普:5,
marginRight:15,
marginBottom:10,
边缘左:100,
边框宽度:0
},
信用证:{已启用:错误},
正在导出:{enabled:false},
标题:{文本:'title'},
xAxis:{
长度:0,
线条颜色:'#999',
线宽:1,
标签:{style:{fontwweight:'bold'}}
},
亚克斯:{
分:0,,
数字:0,
maxPadding:0,
勾选颜色:“#ccc”,
宽度:1,
长度:3,
网格线宽:0,
恩东蒂克:是的,
标题:{文本:'},
标签:{
y:10,
风格:{
字体大小:'8px'
},
格式化程序:函数(){
if(this.isLast){
返回此值。值+'%';
}
否则{
返回此.value;
}
},
已启用:false
}
},
图例:{enabled:false},
工具提示:{
启用:对,
背景颜色:“rgba(255、255、255、85)”,
边框宽度:0,
影子:没错,
样式:{fontSize:'10px',填充:2},
格式化程序:函数(){
返回this.series.name+“:”+Highcharts.numberFormat(this.y,2)+“”;
}
},
打印选项:{
酒吧:{
颜色:“#000”,
影子:错,
边框宽度:0,
},
散布:{
标记:{
符号:'行',
线宽:3,
半径:8,
线条颜色:“#f00”
}
}
}
});
//-------------------------------------------------------
var chart1=新的高点图表。图表({
图表:{renderTo:'container1'},
xAxis:{categories:['Title 1']},
亚克斯:{
最高:100,
标签:{y:10,样式:{fontSize:'8px'},
绘图带:[{from:0,to:70,颜色:'rgba(103103103,.35)},
{从:70到:85,颜色:'rgba(153153,.35)},
{从:85到:100,颜色:'rgba(204204,.35)}]
},
系列:[{name:'Measure',pointWidth:10,data:[80]},
{名称:'Target',类型:'scatter',数据:[90],}]
});

假设您想让图表的高度保持与现在相同,请将div的高度增加30px,将chart.marginTop的高度增加30px

<div id="container1" style="height:66px;width:350px;"></div> 


Highcharts.setOptions({
    chart:{
        defaultSeriesType:'bar',
        marginTop:35,
        marginRight:15,
        marginBottom:10,
        marginLeft:100,        
        borderWidth:0
    },

Highcharts.setOptions({
图表:{
defaultSeriesType:'bar',
玛金托普:35,
marginRight:15,
marginBottom:10,
边缘左:100,
边框宽度:0
},

您的问题是图表上方没有放置标题的空间,因此highcharts将其放置在它可以放置的位置。图表边距在边缘和绘图区域之间设置了固定的间距,因此如果您要使用它们,则需要为绘图区域外的项目留出空间。

尝试在图例中使用y属性设置垂直位置

legend: { 
            y:18
        }

这个答案在手机屏幕上没有用处,因为手机屏幕上的标题可能会延伸到两行。