By default, labels on a Sankey Diagram will be truncated with an ellipsis if they are longer than 150 pixels. This tutorial explores other options for handling long labels.
Here’s a Sankey Diagram with some overly long node names.
Run * ---------------------------------------
* This demo was created using amCharts 4.
* For more information visit:
* https://www.amcharts.com/
* Documentation is available at:
* https://www.amcharts.com/docs/v4/
* ---------------------------------------
am4core . useTheme ( am4themes_animated );
var chart = am4core . create ( " chartdiv " , am4charts . SankeyDiagram );
{ from: " A very long label that we don't want to be truncated " , to: " D " , value: 10 },
{ from: " Here's another rather lenghty text " , to: " D " , value: 8 },
{ from: " Here's another rather lenghty text " , to: " E " , value: 4 },
{ from: " A bit shorter, still long " , to: " E " , value: 3 }
chart . dataFields . fromName = " from " ;
chart . dataFields . toName = " to " ;
chart . dataFields . value = " value " ;
< div id = " chartdiv " ></ div >
-apple-system , BlinkMacSystemFont, " Segoe UI " , Roboto, Helvetica , Arial , sans-serif ,
" Apple Color Emoji " , " Segoe UI Emoji " , " Segoe UI Symbol " ;
wrapping Sankey labels wrapping-sankey-labels
All labels are cut off and not overly informative. Let’s see how we can fix that.
First option is to give labels more space. We can do that by increasing the default width of 150 pixels.
chart . nodes . template . nameLabel . label . width = 200 ;
chart . nodes . template . nameLabel . label . width = 200 ;
{ // ... "nodes": { "nameLabel": { "label": { "width": 200 } } }}
Now we can see that some labels fit, some don’t.
Run * ---------------------------------------
* This demo was created using amCharts 4.
* For more information visit:
* https://www.amcharts.com/
* Documentation is available at:
* https://www.amcharts.com/docs/v4/
* ---------------------------------------
am4core . useTheme ( am4themes_animated );
var chart = am4core . create ( " chartdiv " , am4charts . SankeyDiagram );
{ from: " A very long label that we don't want to be truncated " , to: " D " , value: 10 },
{ from: " Here's another rather lenghty text " , to: " D " , value: 8 },
{ from: " Here's another rather lenghty text " , to: " E " , value: 4 },
{ from: " A bit shorter, still long " , to: " E " , value: 3 }
chart . dataFields . fromName = " from " ;
chart . dataFields . toName = " to " ;
chart . dataFields . value = " value " ;
chart . nodes . template . nameLabel . label . width = 200 ;
< div id = " chartdiv " ></ div >
-apple-system , BlinkMacSystemFont, " Segoe UI " , Roboto, Helvetica , Arial , sans-serif ,
" Apple Color Emoji " , " Segoe UI Emoji " , " Segoe UI Symbol " ;
wrapping Sankey labels wrapping-sankey-labels-2
Let’s explore other options.
We can keep increasing the width until ultimately all labels fit. However, very long labels a) might not fit into chart width, and b) are not easy to read.
In this case, wrapping labels instead of truncating them might be a better option.
chart . nodes . template . nameLabel . label . truncate = false ;chart . nodes . template . nameLabel . label . wrap = true ;
chart . nodes . template . nameLabel . label . truncate = false ; chart . nodes . template . nameLabel . label . wrap = true ;
{ // ... "nodes": { "nameLabel": { "label": { "truncate": false, "wrap": true } } }}
Run * ---------------------------------------
* This demo was created using amCharts 4.
* For more information visit:
* https://www.amcharts.com/
* Documentation is available at:
* https://www.amcharts.com/docs/v4/
* ---------------------------------------
am4core . useTheme ( am4themes_animated );
var chart = am4core . create ( " chartdiv " , am4charts . SankeyDiagram );
{ from: " A very long label that we don't want to be truncated " , to: " D " , value: 10 },
{ from: " Here's another rather lenghty text " , to: " D " , value: 8 },
{ from: " Here's another rather lenghty text " , to: " E " , value: 4 },
{ from: " A bit shorter, still long " , to: " E " , value: 3 }
chart . dataFields . fromName = " from " ;
chart . dataFields . toName = " to " ;
chart . dataFields . value = " value " ;
chart . nodes . template . nameLabel . label . truncate = false ;
chart . nodes . template . nameLabel . label . wrap = true ;
< div id = " chartdiv " ></ div >
-apple-system , BlinkMacSystemFont, " Segoe UI " , Roboto, Helvetica , Arial , sans-serif ,
" Apple Color Emoji " , " Segoe UI Emoji " , " Segoe UI Symbol " ;
wrapping Sankey labels wrapping-sankey-labels-3