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

Pie problems (palette & labels)

3 Answers 78 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Mattia
Top achievements
Rank 2
Mattia asked on 10 Mar 2014, 12:05 PM

Hi,
I created a pie chart and I have two problems..

1. Custom palette
    I want to create a custom palette in code-behind
    This is my code

private void chart1_ItemDataBound(object sender, EventArgs e)
        {
 
            Telerik.Reporting.Processing.Chart procChart = (Telerik.Reporting.Processing.Chart)sender;
            Telerik.Reporting.Chart defChart = (Telerik.Reporting.Chart)procChart.ItemDefinition;
 
            //Find the operations type
            Exception exception = null;
            List<OperationTypeEntity> operationTypes = m_OperationHelper.GetOperationTypes(m_UserId, ref exception);
 
            Palette palette = new Palette();
            palette.Name = "SSCCustomPalette";
 
            foreach (var serie in defChart.Series)
            {
                //Find the operation type color to use for my custom palette
                if (serie.Name.Equals("SeriePerLegenda"))
                {
                    palette.Items.Clear();
                    foreach (var item in serie.Items)
                    {
                        Color color = ColorTranslator.FromHtml(operationTypes.FirstOrDefault(p => p.Description.Equals(item.Name)).Color);
                        palette.Items.Add(new PaletteItem(color, color));
                    }
                }
            }
            chart1.CustomPalettes.Add(palette);
            chart1.SeriesPalette = "SSCCustomPalette";          
             
          }

This code works only after a manual refresh
I can't use need data source event becouse my datasource is already assigned so this events it's not fired.

2. How to print percetage on pie and Description on the legend?
I create a new series and I setted the following:
DataLabelsColum -> Description
DataYColumn -> MyValue
DefaultLabelValue ->#%
Apperance LabelDisplay -> ItemLabels

When I run the report, the legend and the pie labels are the same. I see only the description.

Thanks

 

3 Answers, 1 is accepted

Sort by
0
Nasko
Telerik team
answered on 13 Mar 2014, 10:00 AM
Hello Stefania,

The Chart item is obsolete and is no longer supported. Please use the more advanced Graph item instead to create a Pie Chart.

Also note that it is highly recommended not to use events when designing reports. The reporting engine provides another powerful means to achieve the same functionality. For example instead of using events to accomplish your goals you can take advantage of Expressions, User Functions and Bindings.

The ItemDataBound event occurs after the report item binds to a data source. Thus, it is too late to change the Chart item definition at that point. For more information please refer to the Understanding Events help article.

Setting label format and appearance is elaborated in the Pie Charts (obsolete) help article.

Regards,
Nasko
Telerik
 

DevCraft Q1'14 is here! Watch the online conference to see how this release solves your top-5 .NET challenges. Watch on demand now.

 
0
Mattia
Top achievements
Rank 2
answered on 19 Mar 2014, 03:40 PM
Hi Nasko,
thanks for your reply.
I re-create my pie chart with the graph item and I made some progress.
I still have some problem with the custom palette.
I create my own custom palette function

public static class MyCustomPalette
    {
        [Function(Category = "SSCFunctions", Namespace = "SSC", Description = "Custom Palette")]
        public static ColorPalette SSCPalette(int uID)
        {
            //recupero il cookie con id user e company
            var u = HttpContext.Current.Request.Cookies["u"].Value.ToString().Split('#');
 
            int id = 0; //id user connesso
            if (u != null)
                int.TryParse(u.GetValue(0).ToString(), out id);              
 
 
            ColorPalette customPalette = new ColorPalette();
    
            Exception exception = null;
             OperationsHelper operationHelper = new OperationsHelper();
            List<OperationTypeEntity> operationTypes = operationHelper.GetOperationTypes(id, ref exception).OrderBy(p=>p.Sequential).ToList();
            foreach (OperationTypeEntity item in operationTypes)
            {
                Color color = ColorTranslator.FromHtml(item.Color);
                customPalette.Colors.Add(color);
            }
            return customPalette;
        }
    }

and in my graph Bindings I added a property path "ColorPalette" with the expression "= SSC.SSCPalette(Parameters.userId.Value)"

Without the parameter it worked but if I passed the parameter userId to my function this is always null.. maybe it's too early and the parameter isn't set yet.
Is there some other place where I can call my function?

Thanks
0
Stef
Telerik team
answered on 24 Mar 2014, 03:01 PM
Hello Stefania,

Try using Int64 (long) in the signature of your user function or cast from the common Object type to the expected type.

Let us know if you have any further questions.

Regards,
Stef
Telerik
 

Build cross-platform mobile apps using Visual Studio and .NET. Register for the online webinar on 03/27/2014, 11:00AM US ET.. Seats are limited.

 
Tags
General Discussions
Asked by
Mattia
Top achievements
Rank 2
Answers by
Nasko
Telerik team
Mattia
Top achievements
Rank 2
Stef
Telerik team
Share this question
or