Sir,
I am trying to create a pie chart, then export to word using OpenXml in c#.net. But the problem is,
1) It is exporting but nothing shows ms word 2010 only.
2) I am using ASP.NET MVC4 project, there is a google pie chart which has around 1000 data by representing with multiple color. But I cannot see all details from Word when it is exported at first time. Now it seems color only. How can I see all data when exporting word 2016 at first time?
This is my Google Pie-chart. I am trying to export to word 2016 using OpenXml in ASP.NET MVC4, same as the image looking. Please see below link.
I have used the sample code for this below link.
Kindly answer me.
Advance Thanks.
What I have tried:
CreateWordChart createWordChart = null;
try
{
createWordChart = new CreateWordChart(p);
List<chartsubarea> chartAreas = new List<chartsubarea>();
int j=0;
foreach (var item in charts)
{
if (j == 5)
{
j = 0;
}
chartAreas.Add(new ChartSubArea()
{
Color = (SchemeColorValues)listArr[j],
Label = item.Label,
Value = item.Value1.ToString()
});
j++;
}
createWordChart.CreateChart(chartAreas);
}
catch (Exception ex)
{
}
finally
{
if (createWordChart != null)
{
createWordChart.Dispose();
}
}
public void CreateChart(List<chartsubarea> chartList)
{
MainDocumentPart mainPart = document.AddMainDocumentPart();
mainPart.Document = new Document(new Body());
ChartPart chartPart = mainPart.AddNewPart<chartpart>("rId110");
dc.ChartSpace chartSpace = new dc.ChartSpace();
chartSpace.Append(new dc.EditingLanguage() { Val = "en-us" });
dc.Chart chart = new dc.Chart();
chart.Append(new dc.AutoTitleDeleted() { Val = true });
dc.View3D view3D = new dc.View3D();
view3D.Append(new dc.RotateX() { Val = 30 });
view3D.Append(new dc.RotateY() { Val = 0 });
dc.PlotArea plotArea = new dc.PlotArea();
plotArea.Append(new dc.Layout());
dc.Pie3DChart pie3DChart = new dc.Pie3DChart();
pie3DChart.Append(new dc.VaryColors() { Val = true });
dc.PieChartSeries pieChartSers = new dc.PieChartSeries();
pieChartSers.Append(new dc.Index() { Val = 0U });
pieChartSers.Append(new dc.Order() { Val = 0U });
dc.SeriesText seriesText = new dc.SeriesText();
seriesText.Append(new dc.NumericValue() { Text = "Series" });
uint rowcount = 0;
uint count = UInt32.Parse(chartList.Count.ToString());
string endCell = (count + 1).ToString();
dc.ChartShapeProperties chartShapePros = new dc.ChartShapeProperties();
dc.CategoryAxisData cateAxisData = new dc.CategoryAxisData();
dc.StringReference stringRef = new dc.StringReference();
stringRef.Append(new dc.Formula() { Text = "Main!$A$2:$A$" + endCell });
dc.StringCache stringCache = new dc.StringCache();
stringCache.Append(new dc.PointCount() { Val = count });
dc.Values values = new dc.Values();
dc.NumberReference numRef = new dc.NumberReference();
numRef.Append(new dc.Formula() { Text = "Main!$B$2:$B$" + endCell });
dc.NumberingCache numCache = new dc.NumberingCache();
numCache.Append(new dc.FormatCode() { Text = "General" });
numCache.Append(new dc.PointCount() { Val = count });
foreach (var item in chartList)
{
if (count == 0)
{
chartShapePros.Append(new d.SolidFill(new d.SchemeColor() { Val = item.Color }));
pieChartSers.Append(chartShapePros);
}
else
{
dc.DataPoint dataPoint = new dc.DataPoint();
dataPoint.Append(new dc.Index() { Val = rowcount });
chartShapePros = new dc.ChartShapeProperties();
chartShapePros.Append(new d.SolidFill(new d.SchemeColor() { Val = item.Color }));
dataPoint.Append(chartShapePros);
pieChartSers.Append(dataPoint);
}
dc.StringPoint stringPoint = new dc.StringPoint() { Index = rowcount };
stringPoint.Append(new dc.NumericValue() { Text = item.Label });
stringCache.Append(stringPoint);
dc.NumericPoint numericPoint = new dc.NumericPoint() { Index = rowcount };
numericPoint.Append(new dc.NumericValue() { Text = item.Value });
numCache.Append(numericPoint);
rowcount++;
}
stringRef.Append(stringCache);
cateAxisData.Append(stringRef);
numRef.Append(numCache);
values.Append(numRef);
pieChartSers.Append(cateAxisData);
pieChartSers.Append(values);
pie3DChart.Append(pieChartSers);
plotArea.Append(pie3DChart);
dc.Legend legend = new dc.Legend();
legend.Append(new dc.LegendPosition() { Val = LegendPositionValues.Bottom });
dc.Overlay overlay = new dc.Overlay() { Val = false };
legend.Append(overlay);
dc.TextProperties textPros = new TextProperties();
textPros.Append(new d.BodyProperties());
textPros.Append(new d.ListStyle());
d.Paragraph paragraph = new d.Paragraph();
d.ParagraphProperties paraPros = new d.ParagraphProperties();
d.DefaultParagraphProperties defaultParaPros = new d.DefaultParagraphProperties();
defaultParaPros.Append(new d.LatinFont() { Typeface = "Arial", PitchFamily = 34, CharacterSet = 0 });
defaultParaPros.Append(new d.ComplexScriptFont() { Typeface = "Arial", PitchFamily = 34, CharacterSet = 0 });
paraPros.Append(defaultParaPros);
paragraph.Append(paraPros);
paragraph.Append(new d.EndParagraphRunProperties() { Language = "en-Us" });
textPros.Append(paragraph);
legend.Append(textPros);
chart.Append(view3D);
chart.Append(plotArea);
chart.Append(legend);
chartSpace.Append(chart);
chartShapePros = new dc.ChartShapeProperties();
d.Outline outline = new d.Outline();
outline.Append(new d.NoFill());
chartShapePros.Append(outline);
chartSpace.Append(chartShapePros);
chartPart.ChartSpace = chartSpace;
GeneratePartContent(mainPart);
}
public class ChartSubArea
{
public SchemeColorValues Color { get; set; }
public String Label { get; set; }
public string Value { get; set; }
}</chartpart></chartsubarea></chartsubarea></chartsubarea>