Morris.JS X-Axis Label Height

拟墨画扇 提交于 2019-12-10 19:22:17

问题


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'
    });
}

回答1:


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

$('svg').height(700);



回答2:


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,
  ...
});



回答3:


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




回答4:


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;



回答5:


Simple Add dive like following

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

And add style for above div like

#chart{
  height:400px;
}


来源:https://stackoverflow.com/questions/19715304/morris-js-x-axis-label-height

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!