How to change the AxisX labels

2 posts, 0 answers
  1. diandian82
    diandian82 avatar
    13 posts
    Member since:
    Jul 2007

    Posted 22 Jun 2011 Link to this post

    Hello,

    I want to use the different bar colors in the chart and AxisX labels can be modified.
    Here is my code:

    private void BindData()
            {
                List<TestModal1> lst = new List<TestModal1>();
                lst.Add(new TestModal1() { Name = "FY10 Revenue", Value = 1845 });
                lst.Add(new TestModal1() { Name = "Quota", Value = 2398 });
                lst.Add(new TestModal1() { Name = "ITB", Value = 3487 });
                lst.Add(new TestModal1() { Name = "Called Deals", Value = 3343 });
                lst.Add(new TestModal1() { Name = "Run Rate", Value = 2069.96 });
                lst.Add(new TestModal1() { Name = "Gap", Value = 2234 });
                lst.Add(new TestModal1() { Name = "Pipeline", Value = 2433 });
                chart.ItemsSource = lst;
            }
     
            void InitChart()
            {
                chart.DefaultView.ChartLegend.Visibility = System.Windows.Visibility.Collapsed;
                chart.DefaultView.ChartArea.AxisY.DefaultLabelFormat = "N0";
     
                //SeriesMapping seriesMapping = new SeriesMapping();
                //seriesMapping.SeriesDefinition = new BarSeriesDefinition();
                //seriesMapping.SeriesDefinition.ItemLabelFormat = "N0";
     
                //ItemMapping yMapping = new ItemMapping("Value", DataPointMember.YValue);
                //ItemMapping catMapping = new ItemMapping("Name", DataPointMember.XCategory);
     
                BrushCollection bcBrushes = new BrushCollection() {
                        new SolidColorBrush(Color.FromArgb(255, 198, 156, 109)),
                        new SolidColorBrush(Color.FromArgb(255, 247, 148, 29)),
                        new SolidColorBrush(Color.FromArgb(255, 9, 132, 9)),
                        new SolidColorBrush(Color.FromArgb(255, 5, 5, 254)),
                        new SolidColorBrush(Color.FromArgb(255, 254, 167, 9)),
                        new SolidColorBrush(Color.FromArgb(255, 167, 49, 49)),
                        new SolidColorBrush(Color.FromArgb(255, 86, 116, 185))};
                foreach (Brush item in bcBrushes)
                {
                    chart.PaletteBrushes.Add(item);
                }
                chart.PaletteBrushesUseSolidColors = true;
                chart.DefaultSeriesDefinition.LegendDisplayMode = LegendDisplayMode.DataPointLabel;
                chart.DefaultSeriesDefinition.ItemLabelFormat = "N0";
     
                //seriesMapping.ItemMappings.Add(yMapping);
                //seriesMapping.ItemMappings.Add(catMapping);
                //chart.SeriesMappings.Add(seriesMapping);
            }


    But in my code, I can not change the AxisX labels. Please see attached image, it is a set of numbers.
    However, if use SeriesMapping, the AxisX labels can be modified, but the color for that Series  is solo color, not different colors for different bars.

    Could you please tell me how to implement this?

    Thanks,
    George

  2. Sia
    Admin
    Sia avatar
    667 posts

    Posted 24 Jun 2011 Link to this post

    Hello Guo Song,

    Unfortunately we do not have a built-in support for styling every axis label individually. I have linked your profile with the issue which we have logged in our Public Issues Tracking system. Please vote for it in order to increase its priority.

    As a workaround I can suggest you to go through all labels and set them color corresponding with your custom colors:
    private void RadChart1_LayoutUpdated(object sender, EventArgs e)
    {
        var labels = this.RadChart1.DefaultView.ChartArea.ChildrenOfType<AxisLabel2D>();
        int i = 0;
        foreach (var item in labels)
        {
            item.Foreground = bcBrushes[i++];
        }
    }

    You need to add the logic which correlates with your application's logic.

    Regards,
    Sia
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. DevCraft banner
Back to Top