ejazmusavi
Posts: 5
Joined: Fri Apr 09, 2021 3:20 pm

Stock Chart Resizing with aspect ratio

I am using stock chart in a medical application, Where i want to display patient Heart Rate in the chart.
I want to resize the chart while keeping a specific aspect ratio of 35CM x 8CM. how i can do this.
i need the size ratio for the plot only, not whole container.
I have write my own logic for this, but it does not produce the required result.

Code: Select all

 var width = $('#container2').width();

            var ratio = (width - 40 ) / 1322.84; //1322.84 is 35 cm
            var height = ratio * 302.36220472 + ratio * 151.18110236 + 114 + 100 ; //302.36220472 is 8 cm, 130 is bottom, 114 is top,  151.18110236

            $('#container2').css('height', height);
            data_chart.reflow();
            
            fhrheight = '68%';
         
            if (height < 470) {
                fhrheight = '69%';
            }

            var option = {
                xAxis: [{
                    labels: { style: { fontSize: fontsize + 'px' }},
                    height: fhrheight
                }]
            }

            data_chart.update(option);
User avatar
sebastian.h
Posts: 1734
Joined: Fri Aug 07, 2020 7:08 am

Re: Stock Chart Resizing with aspect ratio

Hi,
We appreciate you reaching out to us.

You have a possibility to set the ratio inside chart.height look at the example.

Code: Select all

    chart: {
        height: (9 / 16 * 100) + '%' // 16:9 ratio
    },

API References:
https://api.highcharts.com/highstock/chart.height

Example how to set height in the ratio:
https://jsfiddle.net/gh/get/library/pur ... t-percent/

Let me know if that was what you were looking for!
Best regards.
Sebastian Hajdus
Highcharts Developer
ejazmusavi
Posts: 5
Joined: Fri Apr 09, 2021 3:20 pm

Re: Stock Chart Resizing with aspect ratio

Thank you so much. It really helped me a lot.
User avatar
sebastian.h
Posts: 1734
Joined: Fri Aug 07, 2020 7:08 am

Re: Stock Chart Resizing with aspect ratio

Hi,
You're welcome! :)

In case of any further questions, feel free to contact us again.
Sebastian Hajdus
Highcharts Developer

Return to “Highcharts Stock”