Morris.JS X-Axis Label Height
Asked Answered
S

5

3

I have a chart generated with Morris.JS but the labels on the x-axis are to long and being cut off due to the limited height of the area showing the labels.

The code below would render a graph that only shows the partial label for "COUNTY PARK ROAD ELEM.". How can I adjust the height of the label area to show the entire text?

The code is as follow

if ($('#IP1').length){ 

    Morris.Bar({
      element: 'IP1',
      data: [           
            {x: 'COUNTY PARK ROAD ELEM.', yIndex: 376.92}                   
      ],
      xkey: 'x',
      ykeys: ['yIndex'],
      labels: ['Index Points'],
      ymax: 500,
      barRatio: 0.2,
      xLabelAngle: 45,
      hideHover: 'auto'
    });
}
Simoniac answered 31/10, 2013 at 19:45 Comment(0)
W
15

The solution that worked for me was to increase the size of the svg tag

$('svg').height(700);
Wandering answered 9/11, 2013 at 9:49 Comment(0)
Y
7

In addition to increasing the height of the element that contains the graph you can also set a padding option on your Morris.Bar to give more room to the labels on the x-axis.

Morris.Bar({
  ...
  padding: 50,
  ...
});
Yaya answered 15/8, 2014 at 17:14 Comment(1)
thank you, spent a lot of time to find way how to remove spaces when axes disable. You design solved my problem!Horned
L
2

Try changing the (currently undocumented) xLabelMargin option to a smaller value - it sets the minimum margin between labels on the x-axis. If labels are closer than the margin, then they won't be drawn.

eg:

Morris.Bar({
  // ...
  xLabelMargin: 10
})

https://github.com/morrisjs/morris.js/issues/235

Liguria answered 17/3, 2016 at 14:50 Comment(0)
D
0

if inside a directive you could use the following:

//in pixels
var heightToAdd = 30;    
var svg = element.find("svg")[0];
svg.height.baseVal.value += heightToAdd;
Dactyl answered 24/7, 2014 at 0:17 Comment(0)
C
0

Simple Add dive like following

<div id="chart"></div>

And add style for above div like

#chart{
  height:400px;
}
Checkpoint answered 9/7, 2018 at 8:11 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.