顧客が望むことをしなければならないこともありますが、以下の方法が最善の方法ではないことはわかっていますが、誰かの助けになるかもしれません)。私が知っているように、HighCharts は 2 つの方法でグラフを視覚化します。これは、 SVG (たとえば、サポートされている Chrome、IE > 8 ブラウザー) およびVML (IE <=8 でサポートされている) です。それぞれの方法には、ソフトブレーキングで必要なこの問題を解決できるポイントが含まれています。
SVG で解決するには、buildText 関数を見つけて、この時点で変更する必要があります。
// 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, '-')));
...
VMLで機能させたい場合。buildText 関数と同じコードを作成する独自の関数を作成できます。
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, '-')));
}
}
}
});
}
}
この後、チャートが読み込まれたときにこの関数を呼び出す必要があります www.highcharts.com/ref/#chart-events--load (申し訳ありませんが、新しいユーザーです)。ページに複数のチャートがある場合は、チャート ID をパラメーターとして softBreaks() 関数に渡すことができます。