Spire.Presentation is a professional PowerPoint® compatible library that enables developers to create, read, write, modify, convert and Print PowerPoint documents. Get free and professional technical support for Spire.Presentation for .NET, Java, Android, C++, Python.

Tue Jan 02, 2018 8:51 pm

I'm trying to create a 3D column chart. I'm able to populate the chart data as needed. How do i assign the series, so the chart is displayed correctly? Do i need to add a series for each year? If so, how do i do this? Any example would be appreciated.







Code: Select all

 var sld = pres.Slides[1];
            IAutoShape title = sld.Shapes[0] as IAutoShape;
            title.TextFrame.Text = "2018 COO Incumbents";
            IChart chart = pres.Slides[1].Shapes[1] as IChart;
            var surveys = Survey.GetRelatedSurveys(this.SurveyID);

            for (int c = 1; c <= surveys.Count; c++)
            {
                chart.ChartData[0, c].Text = surveys[c - 1].SurveyYear.ToString();

            }

            int cnt = 1;
            foreach (var survey in surveys.OrderBy(x => x.SurveyYear))
            {

                var lst = PowerpointHelper.GetMinCriteriaMetPP(Convert.ToInt32(survey.SurveyID), Convert.ToInt32(survey.SurveyBatchID));
                int i = 1;
                foreach (var itm in lst)
                {
                    if (cnt == 1)
                    {
                        chart.ChartData[i, 0].Value = itm.CandidateLastName;
                    }
                    if (lst.Where(x => x.CandidateLastName == chart.ChartData[i, 0].Text).FirstOrDefault() != null)
                        chart.ChartData[i, cnt].Value = Convert.ToDecimal(lst.Where(x => x.CandidateLastName == chart.ChartData[i, 0].Text).FirstOrDefault().Pct);
                    i++;
                }
                cnt++;
            }

            ChartSeriesFormatCollection sers = chart.Series;
            sers[0].Values = chart.ChartData["B2", "C19"];
            chart.Categories.CategoryLabels = chart.ChartData["A2", "A19"];




ghoff12
 
Posts: 11
Joined: Wed Dec 20, 2017 7:12 pm

Wed Jan 03, 2018 6:12 am

Hello,

Thanks for your inquiry.
Yes, you need to assign the series separately using the code below.
Code: Select all
sers[0].Values = chart.ChartData["B2", "B19"];
sers[1].Values = chart.ChartData["C2", "C19"];

Yet after an initial test, I found the chart in the result file has been lost and the MS always prompt the message to ask for repairing the document. I wonder if you have encountered the same issue? To help us with a better investigation, could you please send your sample document to us(support@e-iceblue.com) and share more details?

Sincerely,
Jane
E-iceblue support team
User avatar

Jane.Bai
 
Posts: 1156
Joined: Tue Nov 29, 2016 1:47 am

Mon Jan 08, 2018 2:33 pm

Sorry for the delayed response. (I was out of the office the last few days). I will send you an example when i get back to it. (probably today or tomorrow).

thanks so much for responding so quickly.

Greg

ghoff12
 
Posts: 11
Joined: Wed Dec 20, 2017 7:12 pm

Tue Jan 09, 2018 2:39 am

Hello Greg,

Thanks for your reply.
I'll look forward to your feedback.

Sincerely,
Jane
E-iceblue support team
User avatar

Jane.Bai
 
Posts: 1156
Joined: Tue Nov 29, 2016 1:47 am

Wed Jan 10, 2018 4:41 pm

I was able to add the series per your example. Much Thanks.

However, how do i add the blue line (in attached image). It will need to go at 70% (or a different % depending on the data)

ghoff12
 
Posts: 11
Joined: Wed Dec 20, 2017 7:12 pm

Thu Jan 11, 2018 4:05 am

Hi Greg,

Thank you for responding.
After an initial investigation, we found it might be a little hard to accomplish the task. Generally speaking, there are two ways to get approach it. Once is drawing a line directly at the specific position, the other is adding a series with the same value for all legends and changing the series type to "line". Unfortunately, method two is impossible because your chart is 3D column type while changing series type in 3D combo chart is not allowed in MS standard, which is the main principle that our products are based on. Yet for method 1, it might not be easy to calculate the certain location. Anyway, could you please send the expected document related to the screenshot you attached for our further investigation?

Sincerely,
Jane
E-iceblue support team
User avatar

Jane.Bai
 
Posts: 1156
Joined: Tue Nov 29, 2016 1:47 am

Wed Jan 17, 2018 3:56 pm

Attached is the document. I would need the line at 70%

ghoff12
 
Posts: 11
Joined: Wed Dec 20, 2017 7:12 pm

Thu Jan 18, 2018 6:46 am

Hi,

Thanks for your document.
I'm afraid that you need to draw the line accordingly to accomplish the task. Please refer to the following code to add a line.
Code: Select all
Presentation presentation = new Presentation();
presentation.LoadFromFile("2017 COO (9) - org.pptx");

IChart chart = presentation.Slides[7].Shapes[1] as IChart;
IChart chart1 = presentation.Slides[8].Shapes[1] as IChart;

//Draw line
//You need to specify the x and y coordinate accordingly,
//there's no simple way to calculate at present
float x = 170;
float y = 11.5f;
DrawLine(chart, x, y);
DrawLine(chart1, x, y);

presentation.SaveToFile("12084.pptx", FileFormat.Pptx2007);
System.Diagnostics.Process.Start("12084.pptx");

private static void DrawLine(IChart chart, float x, float y)
{
    IAutoShape shape = chart.Parent.Shapes.AppendShape(ShapeType.Line, new RectangleF(x, y, 420, 420));
    shape.Rotation = -45;
    shape.Line.FillType = FillFormatType.Solid;
    shape.Line.Width = 3;
    shape.Line.SolidFillColor.Color = Color.DarkRed;
}

Attached is the testing file with the line removed and the result file.

Sincerely,
Jane
E-iceblue support team
User avatar

Jane.Bai
 
Posts: 1156
Joined: Tue Nov 29, 2016 1:47 am

Fri Jan 19, 2018 3:57 pm

Thank you! That will work for now. I appreciate it

ghoff12
 
Posts: 11
Joined: Wed Dec 20, 2017 7:12 pm

Mon Jan 22, 2018 1:29 am

Hello,

Thanks for your feedback. If there is any other question, welcome to get it back to us.

Sincerely,
Simon
E-iceblue support team
User avatar

Simon.yang
 
Posts: 620
Joined: Wed Jan 11, 2017 2:03 am

Return to Spire.Presentation