|
1 |
| -# How-to-Add-Arrows-to-the-Chart-Axis-in-WPF-Chart |
2 |
| -Learn how to enhance WPF charts by adding arrows to the chart axes using annotations for improved visualization and clarity. |
| 1 | +# How to Add Arrows to the Chart Axis in WPF Chart |
| 2 | +This article provides a detailed walkthrough on how to add arrows to the axis using Annotations in [WPF Chart](https://www.syncfusion.com/wpf-controls/charts). |
| 3 | + |
| 4 | +The [SfChart](https://help.syncfusion.com/cr/wpf/Syncfusion.UI.Xaml.Charts.SfChart.html) includes support for [Annotations](https://help.syncfusion.com/cr/wpf/Syncfusion.UI.Xaml.Charts.SfChart.html#Syncfusion_UI_Xaml_Charts_SfChart_Annotations), enabling the addition of various types of annotations to enhance chart visualization. Using [Line Annotation](https://help.syncfusion.com/cr/wpf/Syncfusion.UI.Xaml.Charts.LineAnnotation.html) for you can achieves to add arrows to the axis. |
| 5 | + |
| 6 | +The Line Annotation includes following property: |
| 7 | +* [X1](https://help.syncfusion.com/cr/wpf/Syncfusion.UI.Xaml.Charts.Annotation.html#Syncfusion_UI_Xaml_Charts_Annotation_X1) - Represents the X1 Coordinate of the Line Annotation. |
| 8 | +* [X2](https://help.syncfusion.com/cr/wpf/Syncfusion.UI.Xaml.Charts.ShapeAnnotation.html#Syncfusion_UI_Xaml_Charts_ShapeAnnotation_X2) - Represents the X2 Coordinate of the Line Annotation. |
| 9 | +* [Y1](https://help.syncfusion.com/cr/wpf/Syncfusion.UI.Xaml.Charts.Annotation.html#Syncfusion_UI_Xaml_Charts_Annotation_Y1) - Represents the Y1 Coordinate of the Line Annotation. |
| 10 | +* [Y2](https://help.syncfusion.com/cr/wpf/Syncfusion.UI.Xaml.Charts.ShapeAnnotation.html#Syncfusion_UI_Xaml_Charts_ShapeAnnotation_Y2) - Represents the Y2 Coordinate of the Line Annotation. |
| 11 | +* [CanDrag](https://help.syncfusion.com/cr/wpf/Syncfusion.UI.Xaml.Charts.ShapeAnnotation.html#Syncfusion_UI_Xaml_Charts_ShapeAnnotation_CanDrag) - A Boolean value that represent to drag the Annotation. |
| 12 | +* [CanResize](https://help.syncfusion.com/cr/wpf/Syncfusion.UI.Xaml.Charts.ShapeAnnotation.html#Syncfusion_UI_Xaml_Charts_ShapeAnnotation_CanResize) - A Boolean value that represent to resize the Annotation. |
| 13 | +* [CoordinateUnit](https://help.syncfusion.com/cr/wpf/Syncfusion.UI.Xaml.Charts.Annotation.html#Syncfusion_UI_Xaml_Charts_Annotation_CoordinateUnit) - A Coordinate unit value that represent to position the Annotation. |
| 14 | + |
| 15 | +Learn step-by-step instructions and gain insights to add arrows to the axis using annotations. |
| 16 | + |
| 17 | +**Step 1:** Initialize the SfChart and add the series and legend to it as follows. |
| 18 | + |
| 19 | +**XAML** |
| 20 | + |
| 21 | + ```xml |
| 22 | +<chart:SfChart> |
| 23 | + |
| 24 | + <chart:SfChart.Legend> |
| 25 | + <chart:ChartLegend/> |
| 26 | + </chart:SfChart.Legend> |
| 27 | + |
| 28 | + <chart:ColumnSeries ItemsSource="{Binding ElectronicsSales}" |
| 29 | + XBindingPath="Month" |
| 30 | + YBindingPath="Sales" |
| 31 | + ShowTooltip="True" |
| 32 | + EnableAnimation="True" |
| 33 | + Label="Electronic Sales"> |
| 34 | + </chart:ColumnSeries> |
| 35 | + |
| 36 | + <chart:ColumnSeries ItemsSource="{Binding FurnitureSales}" |
| 37 | + XBindingPath="Month" |
| 38 | + YBindingPath="Sales" |
| 39 | + ShowTooltip="True" |
| 40 | + EnableAnimation="True" |
| 41 | + Label="Furniture Sales"> |
| 42 | + </chart:ColumnSeries> |
| 43 | + |
| 44 | +</chart:SfChart> |
| 45 | + ``` |
| 46 | + |
| 47 | + |
| 48 | +**Step 2:** Initialize the LineAnnotation within the Annotations collection of the SfChart, configure it to align with the desired axis, and use the LineCap property to add arrows to the line annotation. |
| 49 | + |
| 50 | +**XAML** |
| 51 | + |
| 52 | + ```xml |
| 53 | +<chart:SfChart> |
| 54 | + |
| 55 | + <chart:SfChart.PrimaryAxis> |
| 56 | + <chart:CategoryAxis EdgeLabelsDrawingMode="Fit" Header="Months" PlotOffsetEnd="15"> |
| 57 | + ...... |
| 58 | + </chart:CategoryAxis> |
| 59 | + </chart:SfChart.PrimaryAxis> |
| 60 | + |
| 61 | + <chart:SfChart.SecondaryAxis> |
| 62 | + <chart:NumericalAxis Minimum="0" Maximum="30000" Interval="10000" Header="Sales Rate" PlotOffsetEnd="5" PlotOffsetStart="5"> |
| 63 | + ...... |
| 64 | + </chart:NumericalAxis> |
| 65 | + </chart:SfChart.SecondaryAxis> |
| 66 | + |
| 67 | + <chart:SfChart.Legend> |
| 68 | + <chart:ChartLegend/> |
| 69 | + </chart:SfChart.Legend> |
| 70 | + |
| 71 | + <chart:SfChart.Annotations> |
| 72 | + <chart:LineAnnotation CoordinateUnit="Axis" X1="-0.5" X2="5.6" Y1="0" Y2="0" Stroke="Black" LineCap="Arrow" CanDrag="True" CanResize="True"/> |
| 73 | + <chart:LineAnnotation CoordinateUnit="Axis" X1="-0.5" X2="-0.5" Y1="0" Y2="30000" Stroke="Black" LineCap="Arrow" CanDrag="True" CanResize="True"/> |
| 74 | + </chart:SfChart.Annotations> |
| 75 | + |
| 76 | +</chart:SfChart> |
| 77 | + ``` |
| 78 | + |
| 79 | + |
| 80 | +**Output:** |
| 81 | + |
| 82 | + |
| 83 | + |
0 commit comments