Posted 25 February 2019, 5:05 pm EST
is there a way of having the plotMargin adjusted automatically based on the formatter?
We could handle the rendered event and set the plot margins dynamically according to the content.
Also how can I retrieve the default plotMargin?
To retrieve the default margins we need to get client rect of chart svg Elemenet and chart’s plot area and then get the difference between the two. Please refer to the following code snippet:
chart.rendered.addHandler(function(s,e){
let chartSvgRect = chart.hostElement.querySelector('svg').getBoundingClientRect();
let plotAreaRect = chart.hostElement.querySelector('.wj-plot-area').getBoundingClientRect();
// rendered margins/ default margins
let left = plotAreaRect.left - chartSvgRect.left,
right = chartSvgRect.right - plotAreaRect.right,
top = plotAreaRect.top - chartSvgRect.top,
bottom = chartSvgRect.bottom - plotAreaRect.bottom;
}
Also I found that manually change the plotMargin will not render the axis title anymore as it will be cut off.
We could also reposition the title in the rendered event.
Please refer to the following updated sample and let us know if you face any further issues:
https://stackblitz.com/edit/js-4a6g43?file=index.js