Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/392.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 旋转的X轴标签与图形本身重叠_Javascript_Graph_Charts_Highcharts - Fatal编程技术网

Javascript 旋转的X轴标签与图形本身重叠

Javascript 旋转的X轴标签与图形本身重叠,javascript,graph,charts,highcharts,Javascript,Graph,Charts,Highcharts,我正在努力使用旋转的x轴标签。如果它们的长度超过5-6个字符,则它们与图形重叠,如您在此处所见: 如果没有显示,您可以在JSFIDLE窗口中复制粘贴下面代码的错误 var chart = new Highcharts.Chart({ chart: { renderTo: 'container', marginLeft: 120 }, xAxis: { categories: ['Jan', '02/03/2011', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'A

我正在努力使用旋转的x轴标签。如果它们的长度超过5-6个字符,则它们与图形重叠,如您在此处所见: 如果没有显示,您可以在JSFIDLE窗口中复制粘贴下面代码的错误

var chart = new Highcharts.Chart({

chart: {
renderTo: 'container',
marginLeft: 120
},

xAxis: {
categories: ['Jan', '02/03/2011', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'], labels : { y : 20, rotation: -45 }
},

yAxis: {
lineWidth: 1,
offset: 0,
labels : { x: -20 },
title: {
text: 'Primary Axis'
},
tickWidth: 1
},

series: [{
data: [29.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4]
}]

});
即使在“标签”属性上设置y值,这也仅适用于较小的标签


有人知道解决方案或者我做错了什么吗?

您可以尝试向x轴标签对象添加align:“right”

e、 g

xAxis:{类别:[Jan',02/03/2011',Mar',Apr',May',Jun',Jul',Aug',Sep',Oct',Nov',Dec'],标签:{y:20,旋转:-45,对齐:'right'},
有时候,你必须按照客户的意愿去做,我知道下面的方法不是最好的方法,但可能会对某人有所帮助)。正如我所知,HighCharts使用两种方式来可视化图表。它是(例如受支持的Chrome,IE>8浏览器)和(受IE支持) xAxis: { categories: ['Jan', '02/03/2011', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'], labels : { y : 20, rotation: -45, align: 'right' } },
// check width and apply soft breaks
if (width) {
...
}
...
var words = span.replace(/\\/g, '\\ ').replace(/-/g, '- ').split(' '),
...
tspan.appendChild(doc.createTextNode(words.join(' ').replace(/\\ /g, '\\').replace(/- /g, '-')));
...
function softBreaks()
        {
            //if ie and vml
            hasSVG = !!document.createElementNS && !!document.createElementNS("http://www.w3.org/2000/svg", "svg").createSVGRect;
            if(!hasSVG)
            {
                //for each
                $.each($('.highcharts-axis > span > div'), function(index, value) {

                    var width = value.parentNode.style.posWidth;
                    var div = value;
                    if (width) {
                        var words = value.innerText.replace(/\//g, '/ ').replace(/\\/g, '\\ ').replace(/\./g, '. ').replace(/-/g, '- ').split(' '),
                        tooLong,
                        actualWidth,
                        rest = [];

                        while (words.length || rest.length) {

                            //actualWidth = value.parentNode.offsetWidth;
                            actualWidth = value.parentNode.scrollWidth; 
                            tooLong = actualWidth > width;

                            if (!tooLong || words.length === 1) { // new line needed
                                words = rest;
                                rest = [];
                                if (words.length) {
                                    div = document.createElement("div");
                                    value.parentNode.appendChild(div);
                                    if (actualWidth > width) { // a single word is pressing it out
                                        width = actualWidth;
                                    }
                                }
                            } else {
                                div.removeChild(div.firstChild);
                                rest.unshift(words.pop());
                            }
                            if (words.length) {
                                div.appendChild(document.createTextNode(words.join(' ').replace(/\/ /g, '/').replace(/\\ /g, '\\').replace(/\. /g, '.').replace(/- /g, '-')));
                            }
                        }
                    }
                });
            }
        }