Search results

Zooming and Panning

Enable Zooming

Chart can be zoomed in three ways.

Pinch zooming is supported only in browsers that support multi-touch gestures. Currently IE11, Chrome and Opera browsers support multi-touch in desktop devices.

default.razor
@using Syncfusion.EJ2.Blazor.Charts

<EjsChart Title="Sales History of Product X">
        <ChartPrimaryXAxis ValueType="Syncfusion.EJ2.Blazor.Charts.ValueType.Category"></ChartPrimaryXAxis>
  
        <ChartZoomSettings EnableMouseWheelZooming="true" EnablePinchZooming="true" EnableSelectionZooming="true"></ChartZoomSettings>
  
        <ChartSeriesCollection>
            <ChartSeries DataSource="@SalesReports" XName="X" YName="YValue" Type="ChartSeriesType.Column"></ChartSeries>
        </ChartSeriesCollection>
</EjsChart>

@code{
    public class ChartData
    {
        public string X;
        public double YValue;
    }


    public List<ChartData> SalesReports = new List<ChartData>
    {
        new ChartData { X= "USA", YValue= 46 },
        new ChartData { X= "GBR", YValue= 27 },
        new ChartData { X= "CHN", YValue= 26 },
        new ChartData { X= "UK", YValue= 26 },
        new ChartData { X= "AUS", YValue= 26 },
        new ChartData { X= "IND", YValue= 26 },
        new ChartData { X= "DEN", YValue= 26 },
        new ChartData { X= "MEX", YValue= 26 },
    };
}

Enable Zooming

After zooming the chart, a zooming toolbar will appear with Zoom,ZoomIn, ZoomOut, Pan and Reset buttons. Selecting the Pan option will allow to pan the chart and selecting the Reset option will reset the zoomed chart.

Modes

The Mode property in ZoomSettings specifies whether the chart is allowed to scale along the horizontal axis or vertical axis. The default value of the mode is XY (both axis).

There are three types of mode.

  • X - Allows us to zoom the chart horizontally.
  • Y - Allows us to zoom the chart vertically.
  • XY - Allows us to zoom the chart both vertically and horizontally.
mode.razor
@using Syncfusion.EJ2.Blazor.Charts

<EjsChart Title="Sales History of Product X">
        <ChartPrimaryXAxis ValueType="Syncfusion.EJ2.Blazor.Charts.ValueType.Category"></ChartPrimaryXAxis>
  
        <ChartZoomSettings EnableSelectionZooming="true" Mode="ZoomMode.X"></ChartZoomSettings>
  
        <ChartSeriesCollection>
            <ChartSeries DataSource="@SalesReports" XName="X" YName="YValue" Type="ChartSeriesType.Column"></ChartSeries>
        </ChartSeriesCollection>
</EjsChart>

@code{
    public class ChartData
    {
        public string X;
        public double YValue;
    }


    public List<ChartData> SalesReports = new List<ChartData>
    {
        new ChartData { X= "USA", YValue= 46 },
        new ChartData { X= "GBR", YValue= 27 },
        new ChartData { X= "CHN", YValue= 26 },
        new ChartData { X= "UK", YValue= 26 },
        new ChartData { X= "AUS", YValue= 26 },
        new ChartData { X= "IND", YValue= 26 },
        new ChartData { X= "DEN", YValue= 26 },
        new ChartData { X= "MEX", YValue= 26 },
    };
}

Toolbar

By default, zoomin, zoomout, pan and reset buttons will be displayed for zoomed chart. You can customize to show your desire tools in the toolbar using ToolbarItems property.

toolbar.razor
@using Syncfusion.EJ2.Blazor.Charts

<EjsChart Width="60%">
        <ChartPrimaryXAxis ValueType="Syncfusion.EJ2.Blazor.Charts.ValueType.Category"></ChartPrimaryXAxis>
  
        <ChartZoomSettings EnableSelectionZooming="true" EnableMouseWheelZooming="true"
                           EnablePinchZooming="true" ToolbarItems="@ToolbarItems">
        </ChartZoomSettings>
  
        <ChartSeriesCollection>
            <ChartSeries DataSource="@SalesReports" XName="X" YName="Y" Type="ChartSeriesType.Area">
            </ChartSeries>
        </ChartSeriesCollection>
</EjsChart>

@code{
public List<ToolbarItems> ToolbarItems = new List<ToolbarItems>() { ToolbarItems.Zoom, ToolbarItems.Reset, ToolbarItems.Pan };
public class ChartData
{
    public string X;
    public double Y;
    public string Color;
}
public List<ChartData> SalesReports = new List<ChartData> 
 {
     new ChartData { X= "South Korea", Y= 39.4, Color="red" },
     new ChartData { X= "India", Y= 61.3, Color="green" },
     new ChartData { X= "Pakistan", Y= 20.4, Color="#ff0097" },
     new ChartData { X= "Germany", Y= 65.1, Color="crimson" },
     new ChartData { X= "Australia", Y= 15.8, Color="blue" },
     new ChartData { X= "Italy", Y= 29.2, Color="darkorange" },
 };
}

Enable pan

Using EnablePan property you can able to pan the zoomed chart without help of toolbar items.

pan.razor
@using Syncfusion.EJ2.Blazor.Charts

<EjsChart Title="Sales History of Product X">
        <ChartPrimaryXAxis ValueType="Syncfusion.EJ2.Blazor.Charts.ValueType.Category" ZoomFactor="0.2" ZoomPosition="0.6"></ChartPrimaryXAxis>
  
        <ChartZoomSettings EnableSelectionZooming="true" Enablepan="true"></ChartZoomSettings>
  
        <ChartSeriesCollection>
            <ChartSeries DataSource="@SalesReports" XName="X" YName="YValue" Type="ChartSeriesType.Column"></ChartSeries>
        </ChartSeriesCollection>
</EjsChart>

@code{
    public class ChartData
    {
        public string X;
        public double YValue;
    }


    public List<ChartData> SalesReports = new List<ChartData>
    {
        new ChartData { X= "USA", YValue= 46 },
        new ChartData { X= "GBR", YValue= 27 },
        new ChartData { X= "CHN", YValue= 26 },
        new ChartData { X= "UK", YValue= 26 },
        new ChartData { X= "AUS", YValue= 26 },
        new ChartData { X= "IND", YValue= 26 },
        new ChartData { X= "DEN", YValue= 26 },
        new ChartData { X= "MEX", YValue= 26 },
    };
}

Enable Scrollbar

Using EnableScrollbar property, you can able to add scrollbar for zoomed chart. Using this scrollbar, you can pan or zoom the chart.

scrollbar.razor
@using Syncfusion.EJ2.Blazor.Charts

<EjsChart title="Sales History of Product X">
        <ChartPrimaryXAxis Title="Years" ValueType="Syncfusion.EJ2.Blazor.Charts.ValueType.DateTime" 
        Skeleton="yMMM" EdgeLabelPlacement="EdgeLabelPlacement.Shift">
            <ChartAxisMajorGridLines Width="0"></ChartAxisMajorGridLines>
        </ChartPrimaryXAxis>
  
        <ChartPrimaryYAxis Title="Profit ($)" RangePadding="ChartRangePadding.None">
            <ChartAxisLineStyle Width="0"></ChartAxisLineStyle>
            <ChartAxisMajorTickLines Width="0"></ChartAxisMajorTickLines>
        </ChartPrimaryYAxis>
  
        <ChartLegendSettings Visible="false"></ChartLegendSettings>
  
        <ChartZoomSettings EnableMouseWheelZooming="true" EnableScrollbar="true" EnablePinchZooming="true" 
        EnableSelectionZooming="true"></ChartZoomSettings>
  
        <ChartSeriesCollection>
            <ChartSeries DataSource="@SalesReports" Name="Warmest" xName="XValue" Width="2" Opacity="1" 
            yName="YValue" Type="ChartSeriesType.Area" Fill="url(#gradient-chart)">
                <ChartSeriesBorder Width="0.5" Color="#00bdae"></ChartSeriesBorder>
            </ChartSeries>
        </ChartSeriesCollection>
  
        <ChartArea>
            <ChartAreaBorder Width="0"></ChartAreaBorder>
        </ChartArea>
</EjsChart>

@code {

    public class ChartData
    {
        public DateTime XValue;
        public double YValue;
    }
    public List<ChartData> SalesReports = new List<ChartData>
   {
        new ChartData { XValue = new DateTime(2000, 02, 11), YValue = 14 },
        new ChartData { XValue = new DateTime(2000, 09, 04), YValue = 20 },
        new ChartData { XValue = new DateTime(2001, 02, 11), YValue = 25 },
        new ChartData { XValue = new DateTime(2001, 09, 16), YValue = 21 },
        new ChartData { XValue = new DateTime(2002, 02, 07), YValue = 13 },
        new ChartData { XValue = new DateTime(2002, 09, 07), YValue = 18 },
        new ChartData { XValue = new DateTime(2003, 02, 11), YValue = 24 },
        new ChartData { XValue = new DateTime(2003, 09, 14), YValue = 23 },
        new ChartData { XValue = new DateTime(2004, 02, 06), YValue = 19 },
        new ChartData { XValue = new DateTime(2004, 09, 06), YValue = 31, },
        new ChartData { XValue = new DateTime(2005, 02, 11), YValue = 39 },
        new ChartData { XValue = new DateTime(2005, 09, 11), YValue = 50 },
        new ChartData { XValue = new DateTime(2006, 02, 11), YValue = 24 },
    };

}
<svg style="height: 0">
    <defs>
        <linearGradient id="gradient-chart" X1="0" X2="0" Y1="0" Y2="1">
            <stop offset="0" />
            <stop offset="1" />
        </linearGradient>
    </defs>
</svg>
<style>

    #gradient-chart stop {
        stop-color: #BDEDE9;
    }

        #gradient-chart stop[offset="0"] {
            stop-opacity: 0.75;
        }

        #gradient-chart stop[offset="1"] {
            stop-opacity: 0;
        }
</style>

Enable Scrollbar

Auto interval on zooming

By using EnableAutoIntervalOnZooming property, the axis interval will get calculated automatically with respect to the zoomed range.

auto-interval.razor
@using Syncfusion.EJ2.Blazor.Charts

<EjsChart Title="Sales History of Product X">
        <ChartPrimaryXAxis ValueType="Syncfusion.EJ2.Blazor.Charts.ValueType.Category" EnableAutoIntervalOnZooming="true"></ChartPrimaryXAxis>
  
        <ChartZoomSettings EnableSelectionZooming="true"></ChartZoomSettings>
  
        <ChartSeriesCollection>
            <ChartSeries DataSource="@SalesReports" XName="X" YName="YValue" Type="ChartSeriesType.Column"></ChartSeries>
        </ChartSeriesCollection>
</EjsChart>

@code{
    public class ChartData
    {
        public string X;
        public double YValue;
    }


    public List<ChartData> SalesReports = new List<ChartData>
    {
        new ChartData { X= "USA", YValue= 46 },
        new ChartData { X= "GBR", YValue= 27 },
        new ChartData { X= "CHN", YValue= 26 },
        new ChartData { X= "UK", YValue= 26 },
        new ChartData { X= "AUS", YValue= 26 },
        new ChartData { X= "IND", YValue= 26 },
        new ChartData { X= "DEN", YValue= 26 },
        new ChartData { X= "MEX", YValue= 26 },
    };
}

See Also