-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to create a space on leftOffset and rightOffset in fixes pixels #1622
Comments
You can't directly set the Here’s how you can do it: Conversion with
|
@SlicedSilver - I have followed the above solution, Its working when am not using Expectation: Actual Behaviour Below is my code
|
You could try something like this if you need to use it with function setPixelOffsetAfterFitContent(chart, offsetInPixels) {
// Temporarily set the right offset to zero to ensure fitContent works correctly
chart.timeScale().applyOptions({ rightOffset: 0 });
// Apply fitContent to fit all data within the chart
chart.timeScale().fitContent();
// Get the current time scale width
const timeScaleWidth = chart.timeScale().width();
// The width of the chart that we want the data to be placed within
const chartPortionWidth = timeScaleWidth - offsetInPixels;
// Get the visible range of bars
const visibleBarsRange = chart.timeScale().getVisibleLogicalRange();
// Ensure the visibleBarsRange is valid
if (visibleBarsRange !== null) {
const numberOfVisibleBars = visibleBarsRange.to - visibleBarsRange.from;
// Calculate desired bar spacing
const desiredBarSpacing = chartPortionWidth / numberOfVisibleBars;
// Calculate right offset in bars
const rightOffsetInBars = offsetInPixels / desiredBarSpacing;
// Apply the determined right offset
chart.timeScale().applyOptions({ rightOffset: rightOffsetInBars });
console.log(`
timeScaleWidth: ${timeScaleWidth},
chartPortionWidth: ${chartPortionWidth},
numberOfVisibleBars: ${numberOfVisibleBars},
desiredBarSpacing: ${desiredBarSpacing},
rightOffsetInBars: ${rightOffsetInBars}
`);
} else {
console.warn("No visible bars range available to calculate offsets.");
}
} |
@SlicedSilver - From the above script, we will not met our expectations. the logs are here when changing intervals no of data Points also varry. For example if i select 30 min => 13 points (point to point time range diff is 30 min), 1min => 374 points (diff is 1 min) , 5min => 76 points(diff is 5 mins b/w the points) and so on. TimeRange should be common for all the intervals 09.15 to 15:30 But, observed from the log numberOfVisibleBars always shows as 151. Hope these information will be useful. Thanks in advance! |
I don't know all the specifics of your implementation and requirements, however I think there is enough information to figure out a solution to your problem. The provided code samples are just illustrative examples and, as you can see, might require some tweaking on your side to make it work for your use case. The current behaviour of If you would like to add this functionality then you would welcome a PR. |
Lightweight Charts™ Version: 4.1.3
Steps/code to reproduce: I would like to leave some padding left side and right side of the chart (inside the axes). So that we found rightOffset from documentation, if we follow the same it adjusts the space in terms of "The margin space in bars" instead of fixed space like 10px on both sides. Below is my code snippet
Actual behavior:
Actually We have time Interval selection based on that chart datapoints will be varry. Based on chart points barspacing and width of bar is adjusting(as per doc we are understanding). based on that bars, rightOffset spacing is adjusting. So the space is chaging whenever we are changing time interval.
Expected behavior:
We need fixed leftOffSet and rightOffset in terms of px not bars size.
Screenshots:
Below image is for 15 min
Below image is for 30 min
Below image is for 5 min
Below image is for 1 min
Expectation should be same fixed space on both ends. Its show stopper for our client
Thanks in advance!!!
The text was updated successfully, but these errors were encountered: