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

problems with StackedBar100

2 Answers 81 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Angelo
Top achievements
Rank 1
Angelo asked on 14 Aug 2009, 05:49 PM
Hi,

I have a StackedBar100 chart in my report, everything works fine, but the problem is the appereance of the percentage result in the Bar.
For example: If I have a bar divided in two or more... the first value appears in the botton of the second part of bar and the other value appears in the top of the second part of the bar. I'd like to see each value appearing inside the correct bar.
Is that possible??

Another Question: I think this code is not good... maybe there is an easy way to do that with the same result.. isnt there??

Thanks...

Code:


    DataTable GetData()
        {
            DataTable dataTable = new DataTable();
            dataTable.Columns.Add("Descricao", typeof(string));
            dataTable.Columns.Add("Qtd1", typeof(int));
            dataTable.Columns.Add("Qtd2", typeof(int));
            dataTable.Rows.Add(new object[] { "A", 3, 5 });
            dataTable.Rows.Add(new object[] { "B", 2, 5 });
            dataTable.Rows.Add(new object[] { "C", 5, 5 });
            return dataTable;
        }


    private void chart2_NeedDataSource(object sender, EventArgs e)
        {
            try
            {
                DataTable dt = new DataTable();
                dt = GetData();


                Telerik.Reporting.Processing.Chart chart = sender as Telerik.Reporting.Processing.Chart;
                chart2.Series.Clear();
                
                ChartSeries s = null;

                for (int i = 0; i < dt.Columns.Count -1; i++)
                {
                    s = new ChartSeries();
                    s.Type = ChartSeriesType.StackedBar100;
                    s.Appearance.LegendDisplayMode = ChartSeriesLegendDisplayMode.Nothing;
                    s.DefaultLabelValue = "#%";
                    
                    
                    chart2.Series.Add(s);

                    foreach (DataRow row in dt.Rows)
                    {
                        ChartSeriesItem item = new ChartSeriesItem();
                        item.YValue = Convert.ToDouble(row[i+1]);
                        s.AddItem(item);

                    }
                    
                }

                foreach (DataRow row in dt.Rows)
                {
                    s.PlotArea.XAxis.AutoScale = false; //false permite gerar o xaxis com os valores que eu definir
                    s.PlotArea.XAxis.AddItem((string)row["Descricao"]);

                }


            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }

2 Answers, 1 is accepted

Sort by
0
Chavdar
Telerik team
answered on 17 Aug 2009, 11:54 AM
Hi Angelo,

To specify the position of the series items labels use the LabelLocation and AlignedPosition properties:

[ChartSeries].Appearance.LabelAppearance.LabelLocation = StyleSeriesItemLabel.ItemLabelLocation.Inside;

[
ChartSeries].Appearance.LabelAppearance.Position.AlignedPosition = AlignedPositions.Center;

The chart can be populated in many different ways depending on the input data. Your approach is not bad and can be little optimized. Here is an updated version:

private void chart1_NeedDataSource(object sender, EventArgs e) 
    { 
        Telerik.Reporting.Processing.Chart chart = (Telerik.Reporting.Processing.Chart)sender; 
        Telerik.Reporting.Chart chartDef = (Telerik.Reporting.Chart)chart.ItemDefinition; 
         
        DataTable dt = new DataTable(); 
        dt = GetData(); 
        chartDef.Series.Clear(); 
 
        for (int i = 1; i < dt.Columns.Count; i++) 
        { 
            Telerik.Reporting.Charting.ChartSeries s = new ChartSeries(); 
            s.Type = ChartSeriesType.StackedBar100; 
            s.Appearance.LegendDisplayMode = ChartSeriesLegendDisplayMode.Nothing; 
            s.DefaultLabelValue = "#%"
            s.Appearance.LabelAppearance.LabelLocation = StyleSeriesItemLabel.ItemLabelLocation.Inside; 
            s.Appearance.LabelAppearance.Position.AlignedPosition = AlignedPositions.Center; 
            chartDef.Series.Add(s); 
 
            foreach (DataRow row in dt.Rows) 
            { 
                ChartSeriesItem item = new ChartSeriesItem(); 
                item.YValue = Convert.ToDouble(row[i]); 
                s.AddItem(item); 
                if (i == 1) // Adding axis items during the population of the first series. 
                { 
                    chartDef.PlotArea.XAxis.AutoScale = false//false permite gerar o xaxis com os valores que eu definir 
                    chartDef.PlotArea.XAxis.AddItem((string)row["Descricao"]); 
                } 
            } 
        } 
    } 




Greetings,
Chavdar
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Angelo
Top achievements
Rank 1
answered on 17 Aug 2009, 12:51 PM
thank you...

It's perfect now...

Tags
General Discussions
Asked by
Angelo
Top achievements
Rank 1
Answers by
Chavdar
Telerik team
Angelo
Top achievements
Rank 1
Share this question
or