DocIO Bar Stacked 100 Chart - Data Labels position

Hello, 

I have a OfficeChartType.Bar_Stacked_100 chart with value data lables. When the percentage is low, the label is crossing the chart area and it looks messy.  Is it possible to place labels on the white space to the right of the plot area?  Thank you very much!  Natalia G.


Here is my code:

 chart.ChartArea.Border.LinePattern = OfficeChartLinePattern.None;
            chart.ChartType = OfficeChartType.Bar_Stacked_100;

            List<BarChartData> dataList = new List<BarChartData>();
            dataList = GetPercentChartData(stateCode, year, type);

            if (dataList.Count > 0)
            {
                chart.SetDataRange(dataList, 1, 1);

                chart.ChartData.SetValue(1, 1, "");
                chart.ChartData.SetValue(1, 2, "");
                chart.ChartData.SetValue(1, 3, "Good");
                chart.ChartData.SetValue(1, 4, "Fair");
                chart.ChartData.SetValue(1, 5, "Poor");
                chart.ChartData.SetValue(1, 6, "Not Rated");

          
                for (int i = 1; i < 4; i++)
                {
                    IOfficeChartDataLabels dataLabels = chart.Series[i].DataPoints.DefaultDataPoint.DataLabels;
                    dataLabels.IsValue = true;
                    dataLabels.NumberFormat = "0.0%";
                    dataLabels.Size = 8;
                    chart.Series[i].SerieFormat.CommonSerieOptions.GapWidth = 20;
                 
                }

                //Sets position for plot area

                chart.PlotArea.Layout.LeftMode = LayoutModes.auto;
                chart.PlotArea.Layout.TopMode = LayoutModes.edge;
                chart.PlotArea.Layout.LayoutTarget = LayoutTargets.outer;
                chart.PlotArea.Layout.Top = 20; //15
                chart.PlotArea.Border.LinePattern = OfficeChartLinePattern.Solid;
                chart.PlotArea.Layout.Height = 50;
                chart.PlotArea.Layout.Width = 255;


                //Sets position for chart legend 
                chart.Legend.Position = OfficeLegendPosition.Bottom;
                chart.Legend.Layout.LeftMode = LayoutModes.factor;
                chart.Legend.Layout.TopMode = LayoutModes.edge;
                chart.Legend.Layout.Top = 80;
                chart.Legend.TextArea.Size = 8;
    
                chart.HasLegend = true;

          
            }


1 Reply

DB Dilli Babu Nandha Gopal Syncfusion Team August 16, 2018 12:25 PM UTC

Hi Natalia, 

Thank you for contacting Syncfusion support. 

As per Microsoft Office chart behavior, the data label can be kept inside the plot area by positioning the data labels. The label’s position is based on the chart data. Since we are unaware of the position to set for data labels before viewing the chart, the label’s position must be changed accordingly based on Microsoft Word/Excel/Presentation view (i.e., look and feel).  

As a workaround, we suggest you to set the data labels position to Inside End for the last series which is out of the plot area which can be done using following code example.  
 
chart.Series[2].DataPoints.DefaultDataPoint.DataLabels.Position = OfficeDataLabelPosition.Inside; 
 

Please let us know if you have any other questions. 

Regards, 
Dilli babu. 


Loader.
Up arrow icon