This is a migrated thread and some comments may be shown as answers.

How to change the AxisX labels

1 Answer 53 Views
Chart
This is a migrated thread and some comments may be shown as answers.
diandian82
Top achievements
Rank 1
diandian82 asked on 22 Jun 2011, 07:55 AM

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

1 Answer, 1 is accepted

Sort by
0
Sia
Telerik team
answered on 24 Jun 2011, 09:51 AM
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
Tags
Chart
Asked by
diandian82
Top achievements
Rank 1
Answers by
Sia
Telerik team
Share this question
or