AxisScroll events are provided for the C1Chart and AxisScrollBar objects to use when you need to determine more information on axis scrolling. For example, using the AxisScroll events you can provide detailed information about which axis is being scrolled, what value the min and max values are before and after scrolling through the data, what type of scrolling is being performed, and the orientation of the scrollbar.
The sender in the AxisScroll event can be either the AxisScrollBar object or the c1Chart1 object. If both the Chart and the AxisScrollBar events are set, the AxisScrollBar event fires first. However, the AxisScroll event fires for all axes, and sets the AxisId property of the AxisScrollEventArgs object to indicate the axis that changed.
The AxisScrollEventArgs class provides data for the AxisScrollEvent which fires whenever the built-in axis scrollbar changes value.
The following table provides information on the AxisScrollEventArgs properties:
Property | Description |
---|---|
AxisID | An enumeration value that identifies the axis being scrolled. |
NewValue | Gets or sets the value of the axis scrollbar as it will be after event completion. The axis scrollbar value indicates the fraction between the minimum and maximum. |
OldValue | Gets the value of the axis scrollbar before the event. The axis scrollbar value indicates the fraction between the minimum and maximum. |
ScrollEventType | Gets a value indicating the type of scroll event such as ThumbPosition, ThumbTrack, EndScroll, LargeIncrement, SmallIncrement, etc. |
ScrollOrientation | Gets a value indicating the orientation of the axis scrollbar. |
The following example demonstrates how to reference all of the properties from the AxisScrollEventArgs class using the AxisScroll event:
To write code in Visual Basic
Visual Basic |
Copy Code
|
---|---|
'type the Imports directive for the namespace Imports C1.Win.C1Chart Public Sub New() InitializeComponent() ' set the chart dock to fill. c1Chart1.Dock = DockStyle.Fill ' setup easy access to the scroll bar object Dim scrollbar As C1.Win.C1Chart.AxisScrollBar = c1Chart1.ChartArea.AxisX.ScrollBar scrollbar.Scale = 0.1 ' set the scale to 1/10th of the full axis width. scrollbar.Visible = True ' make the scrollbar visible. ' add the new AxisScroll event to the AxisScrollBar object. AddHandler scrollbar.AxisScroll, AddressOf XAxis_ScrollEvent ' add the new AxisScroll event to the Chart object. AddHandler c1Chart1.AxisScroll, AddressOf XAxis_ScrollEvent End Sub Public Sub XAxis_ScrollEvent(ByVal sender As Object, ByVal e As C1.Win.C1Chart.AxisScrollEventArgs) Handles C1Chart1.AxisScroll ' AxisScrollEventArgs are similar to that of regular scrollbars ' except that they also include an Axis ID. Dim sb As New StringBuilder() sb.AppendLine("" & Chr(10) & "AxisScroll Event Data") ' sender can be either the AxisScrollBar object or the c1Chart1 object. ' If both the Chart and the AxisScrollBar events are set, the AxisScrollBar. ' event fires first. However, the Chart event fires for ALL axes, and sets ' the AxisId property of the AxisScrollEventArgs object to indicate the axis that changed. sb.AppendLine(" Sender is: " + sender.ToString()) ' AxisId is an enum value that specifies which axis is involved. ' C1.Win.C1Chart.AxisIdEnum sb.AppendLine(" ID: " + e.AxisId.ToString()) ' OldValue and NewValue represent the fraction of the value change. ' from the Axis.Min to Axis.Max. OldValue is before the event. ' NewValue is the fraction that will be after the event. ' Note that NewValue is the only value that can be set. If ' is set NewValue = OldValue, then the event is effectively cancelled. sb.AppendLine(" OldVal: " + e.OldValue.ToString()) sb.AppendLine(" NewVal: " + e.NewValue.ToString()) ' EventType indicates how the scrollbar has been changed. ' SmallIncrement/SmallDecrement indicates the button was pressed. ' LargeIncrement/LargeDecrement indicates the scrollbar was pressed ' between the thumb and the button. ' TrackBar indicates that the scrollbar has been dragged. sb.AppendLine(" EventType: " + e.ScrollEventType.ToString()) sb.AppendLine(" Orientation: " + e.ScrollOrientation.ToString()) System.Diagnostics.Debug.WriteLine(sb.ToString()) End Sub |
To write code in C#
C# |
Copy Code
|
---|---|
//type the using directive for the namespace using C1.Win.C1Chart; public Form1() { InitializeComponent(); // set the chart dock to fill. c1Chart1.Dock = DockStyle.Fill; // setup easy access to the scroll bar object C1.Win.C1Chart.AxisScrollBar scrollbar = c1Chart1.ChartArea.AxisX.ScrollBar; scrollbar.Scale = 0.1; // set the scale to 1/10th of the full axis width. scrollbar.Visible = true; // make the scrollbar visible // add the new AxisScroll event to the AxisScrollBar object. scrollbar.AxisScroll += new C1.Win.C1Chart.AxisScrollEventHandler(XAxis_ScrollEvent); // add the new AxisScroll event to the Chart object c1Chart1.AxisScroll += new C1.Win.C1Chart.AxisScrollEventHandler(XAxis_ScrollEvent); } public void XAxis_ScrollEvent(object sender, C1.Win.C1Chart.AxisScrollEventArgs e) { // AxisScrollEventArgs are similar to that of regular scrollbars // except that they also include an Axis ID. StringBuilder sb = new StringBuilder(); sb.AppendLine("\nAxisScroll Event Data"); // sender can be either the AxisScrollBar object or the c1Chart1 object. // If both the Chart and the AxisScrollBar events are set, the AxisScrollBar // event fires first. However, the Chart event fires for ALL axes, and sets // the AxisId property of the AxisScrollEventArgs object to indicate the // axis that changed. sb.AppendLine(" Sender is: " + sender.ToString()); // AxisId is an enum value that specifies which axis is involved. // C1.Win.C1Chart.AxisIdEnum sb.AppendLine(" ID: " + e.AxisId.ToString()); // OldValue and NewValue represent the fraction of the value change from the Axis.Min to Axis.Max. OldValue is before the event, // NewValue is the fraction that will be after the event. sb.AppendLine(" OldVal: " + e.OldValue.ToString()); sb.AppendLine(" NewVal: " + e.NewValue.ToString()); // EventType indicates how the scrollbar has been changed. // SmallIncrement/SmallDecrement indicates the button was pressed. // LargeIncrement/LargeDecrement indicates the scrollbar was pressed // between the thumb and the button. // TrackBar indicates that the scrollbar has been dragged. sb.AppendLine(" EventType: " + e.ScrollEventType.ToString()); sb.AppendLine(" Orientation: " + e.ScrollOrientation.ToString()); System.Diagnostics.Debug.WriteLine(sb.ToString()); } |
The code outputs the AxisScroll event data similar to the following: