We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy.
Unfortunately, activation email could not send to your email. Please try again.

How to label aach item on an axis in a WPF Syncfusion Chart

Thread ID:

Created:

Updated:

Platform:

Replies:

121503 Dec 21,2015 01:57 PM Dec 22,2015 12:55 AM WPF 1
loading
Tags: Chart
David Schmidt
Asked On December 21, 2015 01:57 PM

I am getting a variable number of labels on my x-axis when trying to show a chart. I want a label for each item on the x-axis. I have uploaded a zip file with a picture of the result I'm seeing. Can anyone help me?

My data source is an ObservableCollection<Agent> and I'm trying to plot Agent.FullName (x-axis) by Agent.UnitsSold (y-axis).

public class Agent : INotifyPropertyChanged
    {
        private string m_lastName;
        private string m_firstName;
        private int m_unitsSold;

        public event PropertyChangedEventHandler PropertyChanged;

        public Agent()
        {
            FirstName = string.Empty;
            LastName = string.Empty;
            UnitsSold = 0;
        }

        public string LastName
        {
            get { return m_lastName; }
            set { m_lastName = value; FirePropertyChanged("LastName"); }
        }

        public string FirstName
        {
            get { return m_firstName; }
            set { m_firstName = value; FirePropertyChanged("FirstName"); }
        }

        public string FullName
        { get { return FirstName + " " + LastName; } }

        public int UnitsSold
        {
            get { return m_unitsSold; }
            set { m_unitsSold = value; FirePropertyChanged("UnitsSold"); }
        }

        private void FirePropertyChanged(string propertyName)
        {
            PropertyChangedEventHandler temp = PropertyChanged;
            if (temp != null)
                temp(this, new PropertyChangedEventArgs(propertyName));
        }
    }



<syncfusion:Chart Name="Chart1"  Margin="0" Background="White">
            <syncfusion:Chart.Header>
                <TextBlock FontSize="20" TextWrapping="Wrap" FontWeight="Regular">Agents- Units Sold</TextBlock>
            </syncfusion:Chart.Header>
            <!--Chart area to present chart segments-->
            <syncfusion:ChartArea IsContextMenuEnabled="False" ContextMenu="{x:Null}" >
                <syncfusion:ChartArea.ColorModel>
                    <syncfusion:ChartStyleModel Palette="Metro"/>
                </syncfusion:ChartArea.ColorModel>
                <!--Chart area Legend declaration-->
                <syncfusion:ChartArea.Legend>
                    <syncfusion:ChartLegend Name="Legend1"  syncfusion:Chart.Dock="{Binding ElementName=Position1, Path=SelectedItem, Mode=TwoWay}"></syncfusion:ChartLegend>
                </syncfusion:ChartArea.Legend>
                <syncfusion:ChartArea.PrimaryAxis>
                    <syncfusion:ChartAxis Header="Agents" RangePadding="Normal"  HidePartialLabel="False"  LabelRotateAngle="90" EdgeLabelsDrawingMode="Shift"></syncfusion:ChartAxis>
                </syncfusion:ChartArea.PrimaryAxis>


                <syncfusion:ChartArea.SecondaryAxis>
                    <syncfusion:ChartAxis Header="Units Sold" EdgeLabelsDrawingMode="Shift"></syncfusion:ChartAxis>
                </syncfusion:ChartArea.SecondaryAxis>
                <!--Chart series declaration-->
                <syncfusion:ChartSeries Name="SeriesA" Type="Column" IsIndexed="True" Unit="Units"  DataSource="{Binding Agents}" BindingPathX="FullName" BindingPathsY="UnitsSold" Label="Office" StrokeThickness="0.5" >

                </syncfusion:ChartSeries>
            </syncfusion:ChartArea>
        </syncfusion:Chart>




Attachment: ChartLabel_Example_1433814a.zip

Rachel A [Syncfusion]
Replied On December 22, 2015 12:55 AM

Hi David,

Thanks for contacting Syncfusion support.

You can achieve the requirement by setting the Interval as 1 in ChartAxis(PrimaryAxis) as in the following code example.

[XAML]

              <syncfusion:ChartArea.PrimaryAxis>

                    <syncfusion:ChartAxis Header="Agents" RangePadding="Normal"  HidePartialLabel="False"  Interval="1"

                                          LabelRotateAngle="90" EdgeLabelsDrawingMode="Shift"></syncfusion:ChartAxis>

                </syncfusion:ChartArea.PrimaryAxis>


Please refer the following UG documentation link to know about ChartAxis
http://help.syncfusion.com/wpf/classic-chart/chart-axis

Output:


Regards,
Rachel.A

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;