如何将节点与高图对齐
How to aligment nodes with highcharts
我正在尝试对齐节点,但我看不到任何选项如何做,
目前我的代码是
Highcharts.chart('container', {
chart: {
type: 'networkgraph',
plotBorderWidth: 1
},
title: {
text: 'Trans-Siberian Railway'
},
subtitle: {
text: 'Barnes-Hut approximation'
},
plotOptions: {
networkgraph: {
layoutAlgorithm: {
enableSimulation: false,
linkLength: 100,
integration: 'verlet',
approximation: 'barnes-hut',
gravitationalConstant: 4,
// Elastic like forces:
attractiveForce: function (d, k) {
return (k - d) / d;
},
/* repulsiveForce: function (d, k) {
return Math.min((k * k) / (d), 100);
} */
}
}
},
series: [{
marker: {
radius: 3,
lineWidth: 1
},
dataLabels: {
enabled: true,
linkFormatter: function () {
return '';
}
},
nodes: [
{
id: 'test',
marker: {
radius: 10
}
},
{
id: 'Moscow',
marker: {
radius: 10
}
}, {
id: 'Beijing',
marker: {
radius: 10
}
},
{
id: 'Brussels',
marker: {
radius: 10
}
},
{
id: 'Bangkok',
marker: {
radius: 10
}
}],
data: [
{ from: 'Bangkok', to: 'Beijing', color: 'blue' },
{ from: 'Moscow', to: 'Beijing', color: 'blue' },
{ from: 'test', to: 'Moscow', color: 'blue' },
{ from: 'Beijing', to: 'Brussels', color: 'blue' },
]
}]
});
代码的结果是:
它仍然没有对齐想要的结果是
您应该能够使用 initialPositions 回调在网络图表中设置固定头寸。为了很好地工作,您还需要将 maxIterations 设置为一些小值,例如 1.
见demo
initialPositions: function() {
var chart = this.series[0].chart,
width = chart.plotWidth,
height = chart.plotHeight;
this.nodes.forEach(function(node, i) {
if(i === 0){
node.plotX = 600;
node.plotY = 100;
}
if(i === 1) {
node.plotX = 350;
node.plotY = 100;
}
if(i === 2){
node.plotX = 200;
node.plotY = 0;
}
if(i === 3) {
node.plotX = 0;
node.plotY = 0;
}
if(i === 4) {
node.plotX = 200;
node.plotY = 200;
}
});
}
API: https://api.highcharts.com/highcharts/series.networkgraph.layoutAlgorithm.maxIterations
API: https://api.highcharts.com/highcharts/series.networkgraph.layoutAlgorithm.initialPositions
如果您想让这些点不可拖动,也许更简单的解决方案是渲染常规折线图?
我正在尝试对齐节点,但我看不到任何选项如何做, 目前我的代码是
Highcharts.chart('container', {
chart: {
type: 'networkgraph',
plotBorderWidth: 1
},
title: {
text: 'Trans-Siberian Railway'
},
subtitle: {
text: 'Barnes-Hut approximation'
},
plotOptions: {
networkgraph: {
layoutAlgorithm: {
enableSimulation: false,
linkLength: 100,
integration: 'verlet',
approximation: 'barnes-hut',
gravitationalConstant: 4,
// Elastic like forces:
attractiveForce: function (d, k) {
return (k - d) / d;
},
/* repulsiveForce: function (d, k) {
return Math.min((k * k) / (d), 100);
} */
}
}
},
series: [{
marker: {
radius: 3,
lineWidth: 1
},
dataLabels: {
enabled: true,
linkFormatter: function () {
return '';
}
},
nodes: [
{
id: 'test',
marker: {
radius: 10
}
},
{
id: 'Moscow',
marker: {
radius: 10
}
}, {
id: 'Beijing',
marker: {
radius: 10
}
},
{
id: 'Brussels',
marker: {
radius: 10
}
},
{
id: 'Bangkok',
marker: {
radius: 10
}
}],
data: [
{ from: 'Bangkok', to: 'Beijing', color: 'blue' },
{ from: 'Moscow', to: 'Beijing', color: 'blue' },
{ from: 'test', to: 'Moscow', color: 'blue' },
{ from: 'Beijing', to: 'Brussels', color: 'blue' },
]
}]
});
代码的结果是:
您应该能够使用 initialPositions 回调在网络图表中设置固定头寸。为了很好地工作,您还需要将 maxIterations 设置为一些小值,例如 1.
见demo
initialPositions: function() {
var chart = this.series[0].chart,
width = chart.plotWidth,
height = chart.plotHeight;
this.nodes.forEach(function(node, i) {
if(i === 0){
node.plotX = 600;
node.plotY = 100;
}
if(i === 1) {
node.plotX = 350;
node.plotY = 100;
}
if(i === 2){
node.plotX = 200;
node.plotY = 0;
}
if(i === 3) {
node.plotX = 0;
node.plotY = 0;
}
if(i === 4) {
node.plotX = 200;
node.plotY = 200;
}
});
}
API: https://api.highcharts.com/highcharts/series.networkgraph.layoutAlgorithm.maxIterations
API: https://api.highcharts.com/highcharts/series.networkgraph.layoutAlgorithm.initialPositions
如果您想让这些点不可拖动,也许更简单的解决方案是渲染常规折线图?