|
//Creates a new Word document
WordDocument document = new WordDocument();
//This method adds one section and one paragraph to the Word document.
document.EnsureMinimal();
//Creates and Appends chart to the paragraph
WChart chart = document.LastParagraph.AppendChart(446, 270);
//Sets chart type
chart.ChartType = OfficeChartType.Pie_Exploded_3D;
IOfficeChartSerie pieSeries = chart.Series.Add();
chart.ChartTitle = "Graphic Results";
//Set rotation value for x-axis of 3D chart.
chart.Rotation= 253;
//Set rotation value for y-axis of 3D chart.
chart.Elevation = 20;
//SetpPerspective value for 3D chart.
chart.Perspective = 30;
//Set false for chart axes are at right angles.
chart.RightAngleAxes = false;
//Sets data for chart
chart.ChartData.SetValue(1, 1, "");
chart.ChartData.SetValue(1, 2, "Graphic Results");
chart.ChartData.SetValue(2, 1, "Phyllis Lapin");
chart.ChartData.SetValue(2, 2, 31);
chart.ChartData.SetValue(3, 1, "Stanley Hudson");
chart.ChartData.SetValue(3, 2, 23);
chart.ChartData.SetValue(4, 1, "Bernard Shah");
chart.ChartData.SetValue(4, 2, 16);
chart.ChartData.SetValue(5, 1, "Patricia Lincoln");
chart.ChartData.SetValue(5, 2, 15);
chart.ChartData.SetValue(6, 1, "Lincoln");
chart.ChartData.SetValue(6, 2, 15);
//Creates a new chart series
pieSeries.Values = chart.ChartData[2, 2, 6, 2];
//Sets data label
pieSeries.DataPoints.DefaultDataPoint.DataLabels.IsPercentage = true;
pieSeries.DataPoints.DefaultDataPoint.DataLabels.Position = OfficeDataLabelPosition.Outside;
chart.ChartArea.Border.LinePattern = OfficeChartLinePattern.None;
chart.HasLegend = false;
//Set forecolor for each data points.
chart.Series[0].DataPoints[0].DataFormat.Fill.ForeColor = Color.FromArgb(255,0,0);
chart.Series[0].DataPoints[1].DataFormat.Fill.ForeColor = Color.FromArgb(128, 128, 128);
chart.Series[0].DataPoints[2].DataFormat.Fill.ForeColor = Color.FromArgb(108, 150, 6);
chart.Series[0].DataPoints[3].DataFormat.Fill.ForeColor = Color.FromArgb(255,255,0);
chart.Series[0].DataPoints[4].DataFormat.Fill.ForeColor = Color.FromArgb(33, 178, 82);
//Saves the document
document.Save("Sample.docx", FormatType.Docx);
//Closes the document
document.Close(); |
Hi Jothi,
I looked sample project which you have sent. I found the issue .
Thank you so much for your great help.
Issue was /'/Creating series' should be next to the '//set chart type'.
But I added '//creating series' code next to '//set data for chart'.
Now I changed the position and working fine.
Thanks again.
Regards,
Rikasa