Sunday, 12 September 2021

Maintain Y axis scale in graph with scroll in the X axis when the dataset grows bigger. Aspect-ratio problem

I have this graph with scroll in the x axis. (chartjs version 2.7.2)

https://jsfiddle.net/r70v96ta/2/

At the end part of the code, where the data is added, you can choose how many records to add:

addData(5, chartTest);

If I add more records the graph goes bigger in the Y axis. I want the data to grow longer in the X axis along with the scroll, but keep the same height. I tried hardcoding heights everywere the canvas is manipulated, but did not get it to work. My ideal would be once the Y axis scale is fixed, to be able to introduce datasets with variable number of records and keep the graph size and scale in Y axis, making the X axis scroll bigger (meaning longer) if the dataset is bigger and viceversa.

Edit:

I also tried to set parameters to the css classes with the purpose of obtaining the Y axis aspect ratio constraint I am after. Seems this could be achieved with the corresponding arragment of the canvas aspect-ratio



from Maintain Y axis scale in graph with scroll in the X axis when the dataset grows bigger. Aspect-ratio problem

No comments:

Post a Comment