Spire.XLS is a professional Excel API that enables developers to create, manage, manipulate, convert and print Excel worksheets. Get free and professional technical support for Spire.XLS for .NET, Java, Android, C++, Python.

Tue Feb 06, 2018 9:17 am

I'm using the free version of Spire and I'm able to create the first of the attachment. My goal is to create the second one but I don't know how to, cant't find info and/or the properties to set.
Can someone help me?
Thanks.
Attachments
pie2.png
Current output
pie2.png (7.52 KiB) Viewed 3951 times
pie1.PNG
Goal
pie1.PNG (57.25 KiB) Viewed 3951 times

emaborsa2
 
Posts: 6
Joined: Tue Feb 06, 2018 7:24 am
Location: Italy

Tue Feb 06, 2018 10:29 am

Dear emaborsa2,

Thanks for your inquiry.
Please use the property Elevation to change the Y rotation.
Code: Select all
            chart.Elevation = 20;

If there is any question, welcome to get it back to us.

Sincerely,
Betsy
E-iceblue support team
User avatar

Betsy.jiang
 
Posts: 3099
Joined: Tue Sep 06, 2016 8:30 am

Tue Feb 06, 2018 10:40 am

Great!

How do I set the gradient colors and the type "Radial" as in the example? I only found chart.ChartArea.Fill.FillType = ShapeFillType.Gradient;

How do I set the background color to the labels? I only found the text color cs.DataPoints[i].DataLabels.Color = Color.White;

How do I set the background color to the legend?

In order to add the shadow I set followings, but it does not work as expected:
Code: Select all
chart.Shadow.Color = Color.Black;
chart.Shadow.Transparency = 80;
chart.Shadow.Size = 102;
chart.Shadow.Angle = 0;
chart.Shadow.Distance = 0;

emaborsa2
 
Posts: 6
Joined: Tue Feb 06, 2018 7:24 am
Location: Italy

Wed Feb 07, 2018 10:49 am

Dear emaborsa2,

Thanks for your response.
1. set gradient colors with the type "Radial" for plot area.
After an initial testing, I found there are some issues, I have logged it in our bug tracking system. We will let you know as soon as there is any update.

2. set the background color for the labels.
Please refer to code below.
Code: Select all
            cs.DataPoints.DefaultDataPoint.DataLabels.FrameFormat.Fill.FillType = ShapeFillType.SolidColor;
            cs.DataPoints.DefaultDataPoint.DataLabels.FrameFormat.Fill.ForeColor = Color.LightSkyBlue;


3. set the background color for the legend.
Sample code for your reference:
Code: Select all
            chart.Legend.FrameFormat.Fill.FillType = ShapeFillType.SolidColor;
            chart.Legend.FrameFormat.Fill.ForeColor = Color.LightSkyBlue;


4. add the shadow for chart.
After an initial testing, I found there are some issues when adding shadow, I have logged it in our bug tracking system.
Once there is any update, we will let you know.

Sincerely,
Betsy
E-iceblue support team
User avatar

Betsy.jiang
 
Posts: 3099
Joined: Tue Sep 06, 2016 8:30 am

Mon Mar 05, 2018 10:12 am

Dear emaborsa2,

Thanks for waiting.
Now the gradient issue and the shadow issue has been fixed in Spire.XLS Pack(Hotfix) Version:8.3.0.
Sample code for setting gradient.
Code: Select all
            XlsShapeFill sha = chart.PlotArea.Fill as XlsShapeFill;
            sha.FillType = ShapeFillType.Gradient;
            sha.IsGradientSupported = true;
            System.Drawing.Color color1 = System.Drawing.Color.FromArgb(255, 0, 0);
            XlsGradientStop stop1 = new XlsGradientStop(new OColor(System.Drawing.Color.Red), 0, 0);
            stop1.Transparency = 100000;
            //type "Radial"
            sha.GradientStops.GradientType = GradientType.Shape;
            sha.GradientStops.Add(stop1);


Sample code for setting the shadow.
Code: Select all
            ChartSerie.DataFormat.Shadow.ShadowOuterType = XLSXChartShadowOuterType.OffsetDiagonalBottomRight;
            ChartSerie.DataFormat.Shadow.Color = System.Drawing.Color.Red;
            ChartSerie.DataFormat.Shadow.Blur = 20;
            ChartSerie.DataFormat.Shadow.Angle = 40;
            ChartSerie.DataFormat.Shadow.Distance = 15;
            ChartSerie.DataFormat.Shadow.Size = 50;
            ChartSerie.DataFormat.Shadow.Transparency = 0;
            ChartSerie.DataFormat.Shadow.HasCustomStyle = true;

Looking forward to your feedback.

Sincerely,
Betsy
E-iceblue support team
User avatar

Betsy.jiang
 
Posts: 3099
Joined: Tue Sep 06, 2016 8:30 am

Mon Apr 30, 2018 3:10 pm

Thanks for your answers.
I did not get exactly what I expected (Goal), but the actually output is fine.

emaborsa2
 
Posts: 6
Joined: Tue Feb 06, 2018 7:24 am
Location: Italy

Tue May 01, 2018 7:48 am

Hello,

Thanks for your feedback.
I did some adjustments to make the resultant effect closer to your goal, please have a check. If there is any question, welcome to write back.
Code: Select all
static void Main(string[] args)
{
    //Create a Workbook
    Workbook workbook = new Workbook();

    //Get the first sheet and set its name
    Worksheet sheet = workbook.Worksheets[0];
    sheet.Name = "Pie Chart";

    //Add a 3d pei chart
    Chart chart = sheet.Charts.Add(ExcelChartType.Pie3DExploded);

    //Set chart data
    CreateChartData(sheet);

    //Set region of chart data
    chart.DataRange = sheet.Range["B1:B2"];
    chart.SeriesDataFromRange = false;

    //Set position of chart
    chart.LeftColumn = 1;
    chart.TopRow = 6;
    chart.RightColumn = 9;
    chart.BottomRow = 25;

    //Chart title
    chart.ChartTitle = "Mitarbeiter";
    chart.ChartTitleArea.IsBold = true;
    chart.ChartTitleArea.Size = 12;

    ChartSerie cs = chart.Series[0];
    cs.CategoryLabels = sheet.Range["A1:A2"];
    cs.Values = sheet.Range["B1:B2"];
    cs.DataPoints.DefaultDataPoint.DataLabels.HasValue = true;

    for (int i = 0; i < chart.Series.Count; i++)
    {
          chart.Series[i].DataPoints.DefaultDataPoint.DataLabels.Color = Color.White;
          chart.Series[i].DataPoints.DefaultDataPoint.DataLabels.FrameFormat.Fill.Texture = GradientTextureType.BrownMarble;
          chart.Series[i].DataPoints.DefaultDataPoint.DataLabels.Position = DataLabelPositionType.Center;
    }
    cs.DataPoints[1].DataFormat.Fill.ForeColor = Color.Red;
    chart.UpdatePositions = true;
    chart.Rotation = 0;
    chart.TopRowOffset = 40; ;
    chart.Elevation = 50;

    //Legend style
    chart.Legend.FrameFormat.Fill.ForeColor = Color.White;
    chart.Legend.FrameFormat.Border.Color = Color.Transparent;

     //Gradient
     chart.ChartArea.Fill.FillType = ShapeFillType.Gradient;
     chart.ChartArea.Fill.PresetGradientType = GradientPresetType.GradChrome;
     chart.ChartArea.Fill.GradientColorType = GradientColorType.OneColor;

     //Shadow
     cs.DataFormat.Shadow.ShadowOuterType = XLSXChartShadowOuterType.OffsetDiagonalBottomRight;
     cs.DataFormat.Shadow.Color = System.Drawing.Color.LightGray;
     cs.DataFormat.Shadow.Blur = 20;
     cs.DataFormat.Shadow.Angle = 30;
     cs.DataFormat.Shadow.Distance = 10;
     cs.DataFormat.Shadow.Size = 40;
     cs.DataFormat.Shadow.Transparency =80;
     cs.DataFormat.Shadow.HasCustomStyle = true;

     //Save and Launch
     workbook.SaveToFile("Output.xlsx", ExcelVersion.Version2010);
     System.Diagnostics.Process.Start("Output.xlsx");
}
private static void CreateChartData(Worksheet sheet)
{
      sheet.Range["A1"].Value = "Anzahl Mitarbeiterinnen";
      sheet.Range["A2"].Value = "Anzahl Mitarbeiter";
      sheet.Range["B1"].NumberValue = 125;
      sheet.Range["B2"].NumberValue = 70;
}

Sincerely,
Nina
E-iceblue support team
User avatar

Nina.Tang
 
Posts: 1182
Joined: Tue Sep 27, 2016 1:06 am

Fri May 04, 2018 8:10 am

Dear emaborsa2,

Greetings from E-iceblue.
Did you try the code provided by Nina ? Did it help you solve your issue ?

Sincerely,
Betsy
E-iceblue support team
User avatar

Betsy.jiang
 
Posts: 3099
Joined: Tue Sep 06, 2016 8:30 am

Return to Spire.XLS