apexcharts / Blazor-ApexCharts

A blazor wrapper for ApexCharts.js
https://apexcharts.github.io/Blazor-ApexCharts
MIT License
788 stars 91 forks source link

How to pre-set zoom area? #371

Closed sam-wheat closed 6 months ago

sam-wheat commented 8 months ago

I have ~2500 data points. I want to render the chart zoomed to the last 1000. Is this possible? I did see this document however it does not describe how to select the elements to include in the zoom area. Thanks.

joadan commented 8 months ago

Have you checked https://apexcharts.github.io/Blazor-ApexCharts/methods/zoomx You should be able to trigger it after OnUpdated event, https://apexcharts.github.io/Blazor-ApexCharts/events/chart-setup

Please note I have not tested this myself.

sam-wheat commented 8 months ago

Thank you @joadan this looks like what I need. However when I use this the chart does not render any series. If at all possible I want to zoom the chart before it is rendered using the entire dataset because it takes too long to render.

<ApexChart OnUpdated="Zoom">  // no data rendered
<ApexChart OnBeforeMount="Zoom">  // no data rendered

private async Task Zoom()
{
    DateTime maxObs = obs.Max(x => x.ObsDate);
    DateTime minObs = obs.Where(x => x.ObsDate < maxObs.AddDays(-50)).Max(x => x.ObsDate);
    await chart.ZoomXAsync(minObs.ToUnixTimeMilliseconds(), maxObs.ToUnixTimeMilliseconds());
}
joadan commented 6 months ago

I close this now, I don' see how the wrapper can do anything more here.