2D Chart for WinForms | ComponentOne
Chart Area and Plot Area Objects / Axes / Axis Scrolling and Scaling / Scrollbar Scaling
In This Topic
    Scrollbar Scaling
    In This Topic

    You can use scaling while you are scrolling through large amounts of data to zoom in on important data.

    Scaling can be implemented at run time by clicking on the scroll bar buttons, or in code, using the ScaleMenuItems property.


    A built-in scale menu appears when the Buttons property is set to ScaleAndScrollButtons (default).

    The following table includes the values' descriptions for the Buttons property:

    Value Description
    NoButtons No buttons appear on the scrollbar.
    ScrollButtons Scroll buttons appear on the scrollbar.
    ScaleButton A scale dropdown button appears. When the dropdown button is clicked a built-in scale menu appears with default scale items.
    ScaleAndScrollButtons The default setting. Both the scroll buttons and scale button appears on the scrollbar.

    If you prefer your own menu for the scale menu, you can create it and assign it to the ScaleMenu property.

    Individual members of the ScaleMenuItem collection can be accessed through design-time using the ScaleMenuItem Collection Editor or through code by using the ScaleMenuItems property to tie the new collection for the scale menu items to the axis scrollbar.

    Using the Designer

    To add scale items to the scale menu at design time, complete the following:

    1. Right-click on the C1Chart control and select Properties from its context menu.
    2. In the Properties window, expand the ChartArea node, expand the AxisX, AxisY, or AxisY2 node, and then expand the ScrollBar.
    3. Click on the ellipsis button next to the ScaleMenuItems property. The ScaleMenuItem Collection Editor appears.
    4. Click Add to add a new item to the collection and then set its Scale and Text properties to the desired value.
    5. Click OK when you are finished.

    Using Code

    To add custom menu items to the scale menu, you can clear the existing collection and add the scale items to the collection like the following:

    To write code in Visual Basic

    Visual Basic
    Copy Code
    With Me.C1Chart1.ChartArea.AxisX.ScrollBar
            .ScaleMenuItems.Clear()
            .ScaleMenuItems.Add(0.1, "1:10")
            .ScaleMenuItems.Add(0.2, "2:10")
            .ScaleMenuItems.Add(0.3, "3:10")
            .ScaleMenuItems.Add(0.4, "4:10")
            .ScaleMenuItems.Add(0.5, "5:10")
            .ScaleMenuItems.Add(0.6, "6:10")
            .ScaleMenuItems.Add(0.7, "7:10")
            .ScaleMenuItems.Add(0.8, "8:10")
            .ScaleMenuItems.Add(0.9, "9:10")
            .ScaleMenuItems.Add(1.0, "10:10")
            .Scale = 0.1'initial value of scale 
            .Visible = True
            End With
    

    To write code in C#

    C#
    Copy Code
    c1Chart1.ChartArea.AxisX.ScrollBar.ScaleMenuItems.Clear();
            c1Chart1.ChartArea.AxisX.ScrollBar.ScaleMenuItems.Add(0.1, "1:10");
            c1Chart1.ChartArea.AxisX.ScrollBar.ScaleMenuItems.Add(0.2, "2:10");
            c1Chart1.ChartArea.AxisX.ScrollBar.ScaleMenuItems.Add(0.3, "3:10");
            c1Chart1.ChartArea.AxisX.ScrollBar.ScaleMenuItems.Add(0.4, "4:10");
            c1Chart1.ChartArea.AxisX.ScrollBar.ScaleMenuItems.Add(0.5, "5:10");
            c1Chart1.ChartArea.AxisX.ScrollBar.ScaleMenuItems.Add(0.6, "6:10");
            c1Chart1.ChartArea.AxisX.ScrollBar.ScaleMenuItems.Add(0.7, "7:10");
            c1Chart1.ChartArea.AxisX.ScrollBar.ScaleMenuItems.Add(0.8, "8:10");
            c1Chart1.ChartArea.AxisX.ScrollBar.ScaleMenuItems.Add(0.9, "9:10");
            c1Chart1.ChartArea.AxisX.ScrollBar.ScaleMenuItems.Add(1.0, "10:10");
            c1Chart1.ChartArea.AxisX.ScrollBar.Scale = 0.1 ;//initial value of scale 
            c1Chart1.ChartArea.AxisX.ScrollBar.Visible = true;
    

    The example given in the code above will clear the existing collection and add new scale menu items to the scrollbar on the x-axis. The ScaleMenuItems property is used to tie the new collection to the axis scrollbar on the chart. The first parameter to the Add method is the scale, which must be a double value between 0 and 1 inclusive. The second parameter, text, is the text that appears in the menu.

    See Also