dynamic height of chart of highchart

孤人 提交于 2019-12-23 04:45:44

问题


It is necessary to automaticly and dynamicly change (update) the height of highcharts's charts depending on the amount rows (example, for horizontal bars) on it.

The height of one element (example, horizontal bar) is constant (for example, 20px). The height of charts with X elements set automaticly (~ 20px * X).


回答1:


You can do this with a little pre-setup.

  • Set variables for:
    • the top and bottom margins
    • the point and group padding
    • the width of the points
    • the number of data points in your data set

Calculate and set the chart's height property accordingly:

var barCount = chartData.length,
    pointWidth = 20,
    marginTop = 70,
    marginRight = 10,
    marginBottom = 50,
    marginLeft = 100,
    groupPadding = 0,
    pointPadding = 0.3,
    chartHeight = marginTop 
                + marginBottom 
                + ((pointWidth * barCount) * (1 + groupPadding + pointPadding));

Fiddle:

  • http://jsfiddle.net/jlbriggs/kpu5d1qf/

(update the dataPoints variable on the page to see it in action)



来源:https://stackoverflow.com/questions/39894055/dynamic-height-of-chart-of-highchart

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