Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Aspose.Slides for .NET
This gist exceeds the recommended number of files (~10). To access all files, please clone this gist.
Added gist for Aspose.Slides for .NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_ActiveX();
string dataVideo = RunExamples.GetDataDir_Video();
// Instantiate Presentation class that represents PPTX file
Presentation presentation = new Presentation(dataDir + "template.pptx");
// Create empty presentation instance
Presentation newPresentation = new Presentation();
// Remove default slide
newPresentation.Slides.RemoveAt(0);
// Clone slide with Media Player ActiveX Control
newPresentation.Slides.InsertClone(0, presentation.Slides[0]);
// Access the Media Player ActiveX control and set the video path
newPresentation.Slides[0].Controls[0].Properties["URL"] = dataVideo + "Wildlife.mp4";
// Save the Presentation
newPresentation.Save(dataDir + "LinkingVideoActiveXControl_out.pptx", Aspose.Slides.Export.SaveFormat.Pptx);
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_ActiveX();
// Accessing the presentation with ActiveX controls
Presentation presentation = new Presentation(dataDir + "ActiveX.pptm");
// Accessing the first slide in presentation
ISlide slide = presentation.Slides[0];
// changing TextBox text
IControl control = slide.Controls[0];
if (control.Name == "TextBox1" && control.Properties != null)
{
string newText = "Changed text";
control.Properties["Value"] = newText;
// changing substitute image. Powerpoint will replace this image during activeX activation, so sometime it's OK to leave image unchanged.
Bitmap image = new Bitmap((int)control.Frame.Width, (int)control.Frame.Height);
Graphics graphics = Graphics.FromImage(image);
Brush brush = new SolidBrush(Color.FromKnownColor(KnownColor.Window));
graphics.FillRectangle(brush, 0, 0, image.Width, image.Height);
brush.Dispose();
System.Drawing.Font font = new System.Drawing.Font(control.Properties["FontName"], 14);
brush = new SolidBrush(Color.FromKnownColor(KnownColor.WindowText));
graphics.DrawString(newText, font, brush, 10, 4);
brush.Dispose();
Pen pen = new Pen(Color.FromKnownColor(KnownColor.ControlDark), 1);
graphics.DrawLines(
pen, new System.Drawing.Point[] { new System.Drawing.Point(0, image.Height - 1), new System.Drawing.Point(0, 0), new System.Drawing.Point(image.Width - 1, 0) });
pen.Dispose();
pen = new Pen(Color.FromKnownColor(KnownColor.ControlDarkDark), 1);
graphics.DrawLines(pen, new System.Drawing.Point[] { new System.Drawing.Point(1, image.Height - 2), new System.Drawing.Point(1, 1), new System.Drawing.Point(image.Width - 2, 1) });
pen.Dispose();
pen = new Pen(Color.FromKnownColor(KnownColor.ControlLight), 1);
graphics.DrawLines(pen, new System.Drawing.Point[]
{
new System.Drawing.Point(1, image.Height - 1), new System.Drawing.Point(image.Width - 1, image.Height - 1),
new System.Drawing.Point(image.Width - 1, 1)
});
pen.Dispose();
pen = new Pen(Color.FromKnownColor(KnownColor.ControlLightLight), 1);
graphics.DrawLines(pen,new System.Drawing.Point[] { new System.Drawing.Point(0, image.Height), new System.Drawing.Point(image.Width, image.Height), new System.Drawing.Point(image.Width, 0) });
pen.Dispose();
graphics.Dispose();
control.SubstitutePictureFormat.Picture.Image = presentation.Images.AddImage(image);
}
// changing Button caption
control = slide.Controls[1];
if (control.Name == "CommandButton1" && control.Properties != null)
{
String newCaption = "MessageBox";
control.Properties["Caption"] = newCaption;
// changing substitute
Bitmap image = new Bitmap((int)control.Frame.Width, (int)control.Frame.Height);
Graphics graphics = Graphics.FromImage(image);
Brush brush = new SolidBrush(Color.FromKnownColor(KnownColor.Control));
graphics.FillRectangle(brush, 0, 0, image.Width, image.Height);
brush.Dispose();
System.Drawing.Font font = new System.Drawing.Font(control.Properties["FontName"], 14);
brush = new SolidBrush(Color.FromKnownColor(KnownColor.WindowText));
SizeF textSize = graphics.MeasureString(newCaption, font, int.MaxValue);
graphics.DrawString(newCaption, font, brush, (image.Width - textSize.Width) / 2, (image.Height - textSize.Height) / 2);
brush.Dispose();
Pen pen = new Pen(Color.FromKnownColor(KnownColor.ControlLightLight), 1);
graphics.DrawLines(pen, new System.Drawing.Point[] { new System.Drawing.Point(0, image.Height - 1), new System.Drawing.Point(0, 0), new System.Drawing.Point(image.Width - 1, 0) });
pen.Dispose();
pen = new Pen(Color.FromKnownColor(KnownColor.ControlLight), 1);
graphics.DrawLines(pen, new System.Drawing.Point[] { new System.Drawing.Point(1, image.Height - 2), new System.Drawing.Point(1, 1), new System.Drawing.Point(image.Width - 2, 1) });
pen.Dispose();
pen = new Pen(Color.FromKnownColor(KnownColor.ControlDark), 1);
graphics.DrawLines(pen,new System.Drawing.Point[]
{
new System.Drawing.Point(1, image.Height - 1),
new System.Drawing.Point(image.Width - 1, image.Height - 1),
new System.Drawing.Point(image.Width - 1, 1)
});
pen.Dispose();
pen = new Pen(Color.FromKnownColor(KnownColor.ControlDarkDark), 1);
graphics.DrawLines(pen,new System.Drawing.Point[] { new System.Drawing.Point(0, image.Height), new System.Drawing.Point(image.Width, image.Height), new System.Drawing.Point(image.Width, 0) });
pen.Dispose();
graphics.Dispose();
control.SubstitutePictureFormat.Picture.Image = presentation.Images.AddImage(image);
}
// Moving ActiveX frames 100 points down
foreach (Control ctl in slide.Controls)
{
IShapeFrame frame = control.Frame;
control.Frame = new ShapeFrame(
frame.X, frame.Y + 100, frame.Width, frame.Height, frame.FlipH, frame.FlipV, frame.Rotation);
}
// Save the presentation with Edited ActiveX Controls
presentation.Save(dataDir + "withActiveX-edited_out.pptm", Aspose.Slides.Export.SaveFormat.Pptm);
// Now removing controls
slide.Controls.Clear();
// Saving the presentation with cleared ActiveX controls
presentation.Save(dataDir + "withActiveX.cleared_out.pptm", Aspose.Slides.Export.SaveFormat.Pptm);
// Create an instance of CAD Metered class
Aspose.Slides.Metered metered = new Aspose.Slides.Metered();
// Access the setMeteredKey property and pass public and private keys as parameters
metered.SetMeteredKey("*****", "*****");
// Get metered data amount before calling API
decimal amountbefore = Aspose.Slides.Metered.GetConsumptionQuantity();
// Display information
Console.WriteLine("Amount Consumed Before: " + amountbefore.ToString());
// Get metered data amount After calling API
decimal amountafter = Aspose.Slides.Metered.GetConsumptionQuantity();
// Display information
Console.WriteLine("Amount Consumed After: " + amountafter.ToString());
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_Charts();
// Creating empty presentation
using (Presentation presentation = new Presentation())
{
// Creating a bubble chart
IChart chart = presentation.Slides[0].Shapes.AddChart(ChartType.Bubble, 50, 50, 400, 300, true);
// Adding custom Error bars and setting its format
IChartSeries series = chart.ChartData.Series[0];
IErrorBarsFormat errBarX = series.ErrorBarsXFormat;
IErrorBarsFormat errBarY = series.ErrorBarsYFormat;
errBarX.IsVisible = true;
errBarY.IsVisible = true;
errBarX.ValueType = ErrorBarValueType.Custom;
errBarY.ValueType = ErrorBarValueType.Custom;
// Accessing chart series data point and setting error bars values for individual point
IChartDataPointCollection points = series.DataPoints;
points.DataSourceTypeForErrorBarsCustomValues.DataSourceTypeForXPlusValues = DataSourceType.DoubleLiterals;
points.DataSourceTypeForErrorBarsCustomValues.DataSourceTypeForXMinusValues = DataSourceType.DoubleLiterals;
points.DataSourceTypeForErrorBarsCustomValues.DataSourceTypeForYPlusValues = DataSourceType.DoubleLiterals;
points.DataSourceTypeForErrorBarsCustomValues.DataSourceTypeForYMinusValues = DataSourceType.DoubleLiterals;
// Setting error bars for chart series points
for (int i = 0; i < points.Count; i++)
{
points[i].ErrorBarsCustomValues.XMinus.AsLiteralDouble = i + 1;
points[i].ErrorBarsCustomValues.XPlus.AsLiteralDouble = i + 1;
points[i].ErrorBarsCustomValues.YMinus.AsLiteralDouble = i + 1;
points[i].ErrorBarsCustomValues.YPlus.AsLiteralDouble = i + 1;
}
// Saving presentation
presentation.Save(dataDir + "ErrorBarsCustomValues_out.pptx", SaveFormat.Pptx);
string dataDir = RunExamples.GetDataDir_Charts();
Presentation pres = new Presentation(dataDir+"testc.pptx");
ISlide slide = pres.Slides[0];
IChart chart = slide.Shapes.AddChart(ChartType.Doughnut, 10, 10, 500, 500, false);
IChartDataWorkbook workBook = chart.ChartData.ChartDataWorkbook;
chart.ChartData.Series.Clear();
chart.ChartData.Categories.Clear();
chart.HasLegend = false;
int seriesIndex = 0;
while (seriesIndex < 15)
{
IChartSeries series = chart.ChartData.Series.Add(workBook.GetCell(0, 0, seriesIndex + 1, "SERIES " + seriesIndex), chart.Type);
series.Explosion = 0;
series.ParentSeriesGroup.DoughnutHoleSize = (byte)20;
series.ParentSeriesGroup.FirstSliceAngle = 351;
seriesIndex++;
}
int categoryIndex = 0;
while (categoryIndex < 15)
{
chart.ChartData.Categories.Add(workBook.GetCell(0, categoryIndex + 1, 0, "CATEGORY " + categoryIndex));
int i = 0;
while (i < chart.ChartData.Series.Count)
{
IChartSeries iCS = chart.ChartData.Series[i];
IChartDataPoint dataPoint = iCS.DataPoints.AddDataPointForDoughnutSeries(workBook.GetCell(0, categoryIndex + 1, i + 1, 1));
dataPoint.Format.Fill.FillType = FillType.Solid;
dataPoint.Format.Line.FillFormat.FillType = FillType.Solid;
dataPoint.Format.Line.FillFormat.SolidFillColor.Color = Color.White;
dataPoint.Format.Line.Width = 1;
dataPoint.Format.Line.Style = LineStyle.Single;
dataPoint.Format.Line.DashStyle = LineDashStyle.Solid;
if (i == chart.ChartData.Series.Count - 1)
{
IDataLabel lbl = dataPoint.Label;
lbl.TextFormat.TextBlockFormat.AutofitType = TextAutofitType.Shape;
lbl.DataLabelFormat.TextFormat.PortionFormat.FontBold = NullableBool.True;
lbl.DataLabelFormat.TextFormat.PortionFormat.LatinFont = new FontData("DINPro-Bold");
lbl.DataLabelFormat.TextFormat.PortionFormat.FontHeight = 12;
lbl.DataLabelFormat.TextFormat.PortionFormat.FillFormat.FillType = FillType.Solid;
lbl.DataLabelFormat.TextFormat.PortionFormat.FillFormat.SolidFillColor.Color = Color.LightGray;
lbl.DataLabelFormat.Format.Line.FillFormat.SolidFillColor.Color = Color.White;
lbl.DataLabelFormat.ShowValue = false;
lbl.DataLabelFormat.ShowCategoryName = true;
lbl.DataLabelFormat.ShowSeriesName = false;
//lbl.DataLabelFormat.ShowLabelAsDataCallout = true;
lbl.DataLabelFormat.ShowLeaderLines = true;
lbl.DataLabelFormat.ShowLabelAsDataCallout = false;
chart.ValidateChartLayout();
lbl.AsILayoutable.X = (float)lbl.AsILayoutable.X + (float)0.5;
lbl.AsILayoutable.Y = (float)lbl.AsILayoutable.Y + (float)0.5;
}
i++;
}
categoryIndex++;
}
pres.Save(dataDir+"chart.pptx", Aspose.Slides.Export.SaveFormat.Pptx);
}
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_Charts();
// Creating empty presentation
using (Presentation presentation = new Presentation())
{
// Creating a bubble chart
IChart chart = presentation.Slides[0].Shapes.AddChart(ChartType.Bubble, 50, 50, 400, 300, true);
// Adding Error bars and setting its format
IErrorBarsFormat errBarX = chart.ChartData.Series[0].ErrorBarsXFormat;
IErrorBarsFormat errBarY = chart.ChartData.Series[0].ErrorBarsYFormat;
errBarX.IsVisible = true;
errBarY.IsVisible = true;
errBarX.ValueType = ErrorBarValueType.Fixed;
errBarX.Value = 0.1f;
errBarY.ValueType = ErrorBarValueType.Percentage;
errBarY.Value = 5;
errBarX.Type = ErrorBarType.Plus;
errBarY.Format.Line.Width = 2;
errBarX.HasEndCap = true;
// Saving presentation
presentation.Save(dataDir + "ErrorBars_out.pptx", SaveFormat.Pptx);
}
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_Charts();
using (Presentation pres = new Presentation())
{
IChart chart = pres.Slides[0].Shapes.AddChart(ChartType.ClusteredColumn, 100, 100, 500, 400);
IAutoShape shape = chart.UserShapes.Shapes.AddAutoShape(ShapeType.Line, 0, chart.Height / 2, chart.Width, 0);
shape.LineFormat.FillFormat.FillType = FillType.Solid;
shape.LineFormat.FillFormat.SolidFillColor.Color = Color.Red;
pres.Save(dataDir + "AddCustomLines.pptx", SaveFormat.Pptx);
}
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_Charts();
using (Presentation presentation = new Presentation(dataDir + "ExistingChart.pptx"))
{
// Get reference of the chart object
var slide = presentation.Slides[0] as Slide;
var shapes = slide.Shapes as ShapeCollection;
var chart = shapes[0] as IChart;
// Animate categories' elements
slide.Timeline.MainSequence.AddEffect(chart, EffectType.Fade, EffectSubtype.None, EffectTriggerType.AfterPrevious);
((Sequence)slide.Timeline.MainSequence).AddEffect(chart, EffectChartMinorGroupingType.ByElementInCategory, 0, 0, EffectType.Appear, EffectSubtype.None, EffectTriggerType.AfterPrevious);
((Sequence)slide.Timeline.MainSequence).AddEffect(chart, EffectChartMinorGroupingType.ByElementInCategory, 0, 1, EffectType.Appear, EffectSubtype.None, EffectTriggerType.AfterPrevious);
((Sequence)slide.Timeline.MainSequence).AddEffect(chart, EffectChartMinorGroupingType.ByElementInCategory, 0, 2, EffectType.Appear, EffectSubtype.None, EffectTriggerType.AfterPrevious);
((Sequence)slide.Timeline.MainSequence).AddEffect(chart, EffectChartMinorGroupingType.ByElementInCategory, 0, 3, EffectType.Appear, EffectSubtype.None, EffectTriggerType.AfterPrevious);
((Sequence)slide.Timeline.MainSequence).AddEffect(chart, EffectChartMinorGroupingType.ByElementInCategory, 1, 0, EffectType.Appear, EffectSubtype.None, EffectTriggerType.AfterPrevious);
((Sequence)slide.Timeline.MainSequence).AddEffect(chart, EffectChartMinorGroupingType.ByElementInCategory, 1, 1, EffectType.Appear, EffectSubtype.None, EffectTriggerType.AfterPrevious);
((Sequence)slide.Timeline.MainSequence).AddEffect(chart, EffectChartMinorGroupingType.ByElementInCategory, 1, 2, EffectType.Appear, EffectSubtype.None, EffectTriggerType.AfterPrevious);
((Sequence)slide.Timeline.MainSequence).AddEffect(chart, EffectChartMinorGroupingType.ByElementInCategory, 1, 3, EffectType.Appear, EffectSubtype.None, EffectTriggerType.AfterPrevious);
((Sequence)slide.Timeline.MainSequence).AddEffect(chart, EffectChartMinorGroupingType.ByElementInCategory, 2, 0, EffectType.Appear, EffectSubtype.None, EffectTriggerType.AfterPrevious);
((Sequence)slide.Timeline.MainSequence).AddEffect(chart, EffectChartMinorGroupingType.ByElementInCategory, 2, 1, EffectType.Appear, EffectSubtype.None, EffectTriggerType.AfterPrevious);
((Sequence)slide.Timeline.MainSequence).AddEffect(chart, EffectChartMinorGroupingType.ByElementInCategory, 2, 2, EffectType.Appear, EffectSubtype.None, EffectTriggerType.AfterPrevious);
((Sequence)slide.Timeline.MainSequence).AddEffect(chart, EffectChartMinorGroupingType.ByElementInCategory, 2, 3, EffectType.Appear, EffectSubtype.None, EffectTriggerType.AfterPrevious);
// Write the presentation file to disk
presentation.Save(dataDir + "AnimatingCategoriesElements_out.pptx", SaveFormat.Pptx);
}
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_Charts();
// Instantiate Presentation class that represents a presentation file
using (Presentation presentation = new Presentation(dataDir + "ExistingChart.pptx"))
{
// Get reference of the chart object
var slide = presentation.Slides[0] as Slide;
var shapes = slide.Shapes as ShapeCollection;
var chart = shapes[0] as IChart;
// Animate the series
slide.Timeline.MainSequence.AddEffect(chart, EffectType.Fade, EffectSubtype.None,
EffectTriggerType.AfterPrevious);
((Sequence)slide.Timeline.MainSequence).AddEffect(chart,
EffectChartMajorGroupingType.BySeries, 0,
EffectType.Appear, EffectSubtype.None, EffectTriggerType.AfterPrevious);
((Sequence)slide.Timeline.MainSequence).AddEffect(chart,
EffectChartMajorGroupingType.BySeries, 1,
EffectType.Appear, EffectSubtype.None, EffectTriggerType.AfterPrevious);
((Sequence)slide.Timeline.MainSequence).AddEffect(chart,
EffectChartMajorGroupingType.BySeries, 2,
EffectType.Appear, EffectSubtype.None, EffectTriggerType.AfterPrevious);
((Sequence)slide.Timeline.MainSequence).AddEffect(chart,
EffectChartMajorGroupingType.BySeries, 3,
EffectType.Appear, EffectSubtype.None, EffectTriggerType.AfterPrevious);
// Write the modified presentation to disk
presentation.Save(dataDir + "AnimatingSeries_out.pptx", SaveFormat.Pptx);
}
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_Charts();
// Load a presentation
using (Presentation presentation = new Presentation(dataDir + "ExistingChart.pptx"))
{
// Get reference of the chart object
var slide = presentation.Slides[0] as Slide;
var shapes = slide.Shapes as ShapeCollection;
var chart = shapes[0] as IChart;
// Animate series elements
slide.Timeline.MainSequence.AddEffect(chart, EffectType.Fade, EffectSubtype.None, EffectTriggerType.AfterPrevious);
((Sequence)slide.Timeline.MainSequence).AddEffect(chart, EffectChartMinorGroupingType.ByElementInSeries, 0, 0, EffectType.Appear, EffectSubtype.None, EffectTriggerType.AfterPrevious);
((Sequence)slide.Timeline.MainSequence).AddEffect(chart, EffectChartMinorGroupingType.ByElementInSeries, 0, 1, EffectType.Appear, EffectSubtype.None, EffectTriggerType.AfterPrevious);
((Sequence)slide.Timeline.MainSequence).AddEffect(chart, EffectChartMinorGroupingType.ByElementInSeries, 0, 2, EffectType.Appear, EffectSubtype.None, EffectTriggerType.AfterPrevious);
((Sequence)slide.Timeline.MainSequence).AddEffect(chart, EffectChartMinorGroupingType.ByElementInSeries, 0, 3, EffectType.Appear, EffectSubtype.None, EffectTriggerType.AfterPrevious);
((Sequence)slide.Timeline.MainSequence).AddEffect(chart, EffectChartMinorGroupingType.ByElementInSeries, 1, 0, EffectType.Appear, EffectSubtype.None, EffectTriggerType.AfterPrevious);
((Sequence)slide.Timeline.MainSequence).AddEffect(chart, EffectChartMinorGroupingType.ByElementInSeries, 1, 1, EffectType.Appear, EffectSubtype.None, EffectTriggerType.AfterPrevious);
((Sequence)slide.Timeline.MainSequence).AddEffect(chart, EffectChartMinorGroupingType.ByElementInSeries, 1, 2, EffectType.Appear, EffectSubtype.None, EffectTriggerType.AfterPrevious);
((Sequence)slide.Timeline.MainSequence).AddEffect(chart, EffectChartMinorGroupingType.ByElementInSeries, 1, 3, EffectType.Appear, EffectSubtype.None, EffectTriggerType.AfterPrevious);
((Sequence)slide.Timeline.MainSequence).AddEffect(chart, EffectChartMinorGroupingType.ByElementInSeries, 2, 0, EffectType.Appear, EffectSubtype.None, EffectTriggerType.AfterPrevious);
((Sequence)slide.Timeline.MainSequence).AddEffect(chart, EffectChartMinorGroupingType.ByElementInSeries, 2, 1, EffectType.Appear, EffectSubtype.None, EffectTriggerType.AfterPrevious);
((Sequence)slide.Timeline.MainSequence).AddEffect(chart, EffectChartMinorGroupingType.ByElementInSeries, 2, 2, EffectType.Appear, EffectSubtype.None, EffectTriggerType.AfterPrevious);
((Sequence)slide.Timeline.MainSequence).AddEffect(chart, EffectChartMinorGroupingType.ByElementInSeries, 2, 3, EffectType.Appear, EffectSubtype.None, EffectTriggerType.AfterPrevious);
// Write the presentation file to disk
presentation.Save(dataDir + "AnimatingSeriesElements_out.pptx", SaveFormat.Pptx);
}
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_Charts();
// Create an instance of Presentation class
Presentation presentation = new Presentation();
// Access first slide
ISlide slide = presentation.Slides[0];
// Add chart with default data
IChart chart = slide.Shapes.AddChart(ChartType.ClusteredColumn, 0, 0, 500, 500);
// Set first series to Show Values
chart.ChartData.Series[0].Labels.DefaultDataLabelFormat.ShowValue = true;
// Setting the index of chart data sheet
int defaultWorksheetIndex = 0;
// Getting the chart data worksheet
IChartDataWorkbook fact = chart.ChartData.ChartDataWorkbook;
// Delete default generated series and categories
chart.ChartData.Series.Clear();
chart.ChartData.Categories.Clear();
int s = chart.ChartData.Series.Count;
s = chart.ChartData.Categories.Count;
// Adding new series
chart.ChartData.Series.Add(fact.GetCell(defaultWorksheetIndex, 0, 1, "Series 1"), chart.Type);
chart.ChartData.Series.Add(fact.GetCell(defaultWorksheetIndex, 0, 2, "Series 2"), chart.Type);
// Adding new categories
chart.ChartData.Categories.Add(fact.GetCell(defaultWorksheetIndex, 1, 0, "Caetegoty 1"));
chart.ChartData.Categories.Add(fact.GetCell(defaultWorksheetIndex, 2, 0, "Caetegoty 2"));
chart.ChartData.Categories.Add(fact.GetCell(defaultWorksheetIndex, 3, 0, "Caetegoty 3"));
// Take first chart series
IChartSeries series = chart.ChartData.Series[0];
// Now populating series data
series.DataPoints.AddDataPointForBarSeries(fact.GetCell(defaultWorksheetIndex, 1, 1, 20));
series.DataPoints.AddDataPointForBarSeries(fact.GetCell(defaultWorksheetIndex, 2, 1, 50));
series.DataPoints.AddDataPointForBarSeries(fact.GetCell(defaultWorksheetIndex, 3, 1, 30));
// Setting automatic fill color for series
series.Format.Fill.FillType = FillType.NotDefined;
// Take second chart series
series = chart.ChartData.Series[1];
// Now populating series data
series.DataPoints.AddDataPointForBarSeries(fact.GetCell(defaultWorksheetIndex, 1, 2, 30));
series.DataPoints.AddDataPointForBarSeries(fact.GetCell(defaultWorksheetIndex, 2, 2, 10));
series.DataPoints.AddDataPointForBarSeries(fact.GetCell(defaultWorksheetIndex, 3, 2, 60));
// Setting fill color for series
series.Format.Fill.FillType = FillType.Solid;
series.Format.Fill.SolidFillColor.Color = Color.Gray;
// Save presentation with chart
presentation.Save(dataDir + "AutomaticColor_out.pptx", SaveFormat.Pptx);
public static void Run()
{
string dataDir = RunExamples.GetDataDir_Charts();
using (Presentation pres = new Presentation(dataDir+"test.pptx"))
{
IChart chart = pres.Slides[0].Shapes.AddChart(ChartType.BoxAndWhisker, 50, 50, 500, 400);
chart.ChartData.Categories.Clear();
chart.ChartData.Series.Clear();
IChartDataWorkbook wb = chart.ChartData.ChartDataWorkbook;
wb.Clear(0);
chart.ChartData.Categories.Add(wb.GetCell(0, "A1", "Category 1"));
chart.ChartData.Categories.Add(wb.GetCell(0, "A2", "Category 1"));
chart.ChartData.Categories.Add(wb.GetCell(0, "A3", "Category 1"));
chart.ChartData.Categories.Add(wb.GetCell(0, "A4", "Category 1"));
chart.ChartData.Categories.Add(wb.GetCell(0, "A5", "Category 1"));
chart.ChartData.Categories.Add(wb.GetCell(0, "A6", "Category 1"));
IChartSeries series = chart.ChartData.Series.Add(ChartType.BoxAndWhisker);
series.QuartileMethod = QuartileMethodType.Exclusive;
series.ShowMeanLine = true;
series.ShowMeanMarkers = true;
series.ShowInnerPoints = true;
series.ShowOutlierPoints = true;
series.DataPoints.AddDataPointForBoxAndWhiskerSeries(wb.GetCell(0, "B1", 15));
series.DataPoints.AddDataPointForBoxAndWhiskerSeries(wb.GetCell(0, "B2", 41));
series.DataPoints.AddDataPointForBoxAndWhiskerSeries(wb.GetCell(0, "B3", 16));
series.DataPoints.AddDataPointForBoxAndWhiskerSeries(wb.GetCell(0, "B4", 10));
series.DataPoints.AddDataPointForBoxAndWhiskerSeries(wb.GetCell(0, "B5", 23));
series.DataPoints.AddDataPointForBoxAndWhiskerSeries(wb.GetCell(0, "B6", 16));
pres.Save("BoxAndWhisker.pptx", SaveFormat.Pptx);
}
}
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_Charts();
using (Presentation presentation = new Presentation(dataDir + "ExistingChart.pptx"))
{
IChart chart = presentation.Slides[0].Shapes[0] as IChart;
chart.Axes.HorizontalAxis.CategoryAxisType = CategoryAxisType.Date;
chart.Axes.HorizontalAxis.IsAutomaticMajorUnit = false;
chart.Axes.HorizontalAxis.MajorUnit = 1;
chart.Axes.HorizontalAxis.MajorUnitScale = TimeUnitType.Months;
presentation.Save(dataDir + "ChangeChartCategoryAxis_out.pptx", SaveFormat.Pptx);
}
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_Charts();
using (Presentation pres = new Presentation())
{
IChart chart = pres.Slides[0].Shapes.AddChart(ChartType.ClusteredColumn, 50, 50, 600, 400);
IChartDataPoint point = chart.ChartData.Series[0].DataPoints[0];
point.Format.Fill.FillType = FillType.Solid;
point.Format.Fill.SolidFillColor.Color = Color.Blue;
pres.Save(dataDir + "output.pptx", SaveFormat.Pptx);
}
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_Charts();
// Create directory if it is not already present.
bool IsExists = System.IO.Directory.Exists(dataDir);
if (!IsExists)
System.IO.Directory.CreateDirectory(dataDir);
// Instantiating presentation// Instantiating presentation
Presentation pres = new Presentation();
// Accessing the first slide
ISlide slide = pres.Slides[0];
// Adding the sample chart
IChart chart = slide.Shapes.AddChart(ChartType.LineWithMarkers, 50, 50, 500, 400);
// Setting Chart Titile
chart.HasTitle = true;
chart.ChartTitle.AddTextFrameForOverriding("");
IPortion chartTitle = chart.ChartTitle.TextFrameForOverriding.Paragraphs[0].Portions[0];
chartTitle.Text = "Sample Chart";
chartTitle.PortionFormat.FillFormat.FillType = FillType.Solid;
chartTitle.PortionFormat.FillFormat.SolidFillColor.Color = Color.Gray;
chartTitle.PortionFormat.FontHeight = 20;
chartTitle.PortionFormat.FontBold = NullableBool.True;
chartTitle.PortionFormat.FontItalic = NullableBool.True;
// Setting Major grid lines format for value axis
chart.Axes.VerticalAxis.MajorGridLinesFormat.Line.FillFormat.FillType = FillType.Solid;
chart.Axes.VerticalAxis.MajorGridLinesFormat.Line.FillFormat.SolidFillColor.Color = Color.Blue;
chart.Axes.VerticalAxis.MajorGridLinesFormat.Line.Width = 5;
chart.Axes.VerticalAxis.MajorGridLinesFormat.Line.DashStyle = LineDashStyle.DashDot;
// Setting Minor grid lines format for value axis
chart.Axes.VerticalAxis.MinorGridLinesFormat.Line.FillFormat.FillType = FillType.Solid;
chart.Axes.VerticalAxis.MinorGridLinesFormat.Line.FillFormat.SolidFillColor.Color = Color.Red;
chart.Axes.VerticalAxis.MinorGridLinesFormat.Line.Width = 3;
// Setting value axis number format
chart.Axes.VerticalAxis.IsNumberFormatLinkedToSource = false;
chart.Axes.VerticalAxis.DisplayUnit = DisplayUnitType.Thousands;
chart.Axes.VerticalAxis.NumberFormat = "0.0%";
// Setting chart maximum, minimum values
chart.Axes.VerticalAxis.IsAutomaticMajorUnit = false;
chart.Axes.VerticalAxis.IsAutomaticMaxValue = false;
chart.Axes.VerticalAxis.IsAutomaticMinorUnit = false;
chart.Axes.VerticalAxis.IsAutomaticMinValue = false;
chart.Axes.VerticalAxis.MaxValue = 15f;
chart.Axes.VerticalAxis.MinValue = -2f;
chart.Axes.VerticalAxis.MinorUnit = 0.5f;
chart.Axes.VerticalAxis.MajorUnit = 2.0f;
// Setting Value Axis Text Properties
IChartPortionFormat txtVal = chart.Axes.VerticalAxis.TextFormat.PortionFormat;
txtVal.FontBold = NullableBool.True;
txtVal.FontHeight = 16;
txtVal.FontItalic = NullableBool.True;
txtVal.FillFormat.FillType = FillType.Solid; ;
txtVal.FillFormat.SolidFillColor.Color = Color.DarkGreen;
txtVal.LatinFont = new FontData("Times New Roman");
// Setting value axis title
chart.Axes.VerticalAxis.HasTitle = true;
chart.Axes.VerticalAxis.Title.AddTextFrameForOverriding("");
IPortion valtitle = chart.Axes.VerticalAxis.Title.TextFrameForOverriding.Paragraphs[0].Portions[0];
valtitle.Text = "Primary Axis";
valtitle.PortionFormat.FillFormat.FillType = FillType.Solid;
valtitle.PortionFormat.FillFormat.SolidFillColor.Color = Color.Gray;
valtitle.PortionFormat.FontHeight = 20;
valtitle.PortionFormat.FontBold = NullableBool.True;
valtitle.PortionFormat.FontItalic = NullableBool.True;
// Setting value axis line format : Now Obselete
// chart.Axes.VerticalAxis.aVerticalAxis.l.AxisLine.Width = 10;
// chart.Axes.VerticalAxis.AxisLine.FillFormat.FillType = FillType.Solid;
// Chart.Axes.VerticalAxis.AxisLine.FillFormat.SolidFillColor.Color = Color.Red;
// Setting Major grid lines format for Category axis
chart.Axes.HorizontalAxis.MajorGridLinesFormat.Line.FillFormat.FillType = FillType.Solid;
chart.Axes.HorizontalAxis.MajorGridLinesFormat.Line.FillFormat.SolidFillColor.Color = Color.Green;
chart.Axes.HorizontalAxis.MajorGridLinesFormat.Line.Width = 5;
// Setting Minor grid lines format for Category axis
chart.Axes.HorizontalAxis.MinorGridLinesFormat.Line.FillFormat.FillType = FillType.Solid;
chart.Axes.HorizontalAxis.MinorGridLinesFormat.Line.FillFormat.SolidFillColor.Color = Color.Yellow;
chart.Axes.HorizontalAxis.MinorGridLinesFormat.Line.Width = 3;
// Setting Category Axis Text Properties
IChartPortionFormat txtCat = chart.Axes.HorizontalAxis.TextFormat.PortionFormat;
txtCat.FontBold = NullableBool.True;
txtCat.FontHeight = 16;
txtCat.FontItalic = NullableBool.True;
txtCat.FillFormat.FillType = FillType.Solid; ;
txtCat.FillFormat.SolidFillColor.Color = Color.Blue;
txtCat.LatinFont = new FontData("Arial");
// Setting Category Titile
chart.Axes.HorizontalAxis.HasTitle = true;
chart.Axes.HorizontalAxis.Title.AddTextFrameForOverriding("");
IPortion catTitle = chart.Axes.HorizontalAxis.Title.TextFrameForOverriding.Paragraphs[0].Portions[0];
catTitle.Text = "Sample Category";
catTitle.PortionFormat.FillFormat.FillType = FillType.Solid;
catTitle.PortionFormat.FillFormat.SolidFillColor.Color = Color.Gray;
catTitle.PortionFormat.FontHeight = 20;
catTitle.PortionFormat.FontBold = NullableBool.True;
catTitle.PortionFormat.FontItalic = NullableBool.True;
// Setting category axis lable position
chart.Axes.HorizontalAxis.TickLabelPosition = TickLabelPositionType.Low;
// Setting category axis lable rotation angle
chart.Axes.HorizontalAxis.TickLabelRotationAngle = 45;
// Setting Legends Text Properties
IChartPortionFormat txtleg = chart.Legend.TextFormat.PortionFormat;
txtleg.FontBold = NullableBool.True;
txtleg.FontHeight = 16;
txtleg.FontItalic = NullableBool.True;
txtleg.FillFormat.FillType = FillType.Solid; ;
txtleg.FillFormat.SolidFillColor.Color = Color.DarkRed;
// Set show chart legends without overlapping chart
chart.Legend.Overlay = true;
// Ploting first series on secondary value axis
// Chart.ChartData.Series[0].PlotOnSecondAxis = true;
// Setting chart back wall color
chart.BackWall.Thickness = 1;
chart.BackWall.Format.Fill.FillType = FillType.Solid;
chart.BackWall.Format.Fill.SolidFillColor.Color = Color.Orange;
chart.Floor.Format.Fill.FillType = FillType.Solid;
chart.Floor.Format.Fill.SolidFillColor.Color = Color.Red;
// Setting Plot area color
chart.PlotArea.Format.Fill.FillType = FillType.Solid;
chart.PlotArea.Format.Fill.SolidFillColor.Color = Color.LightCyan;
// Save Presentation
pres.Save(dataDir + "FormattedChart_out.pptx", SaveFormat.Pptx);
string dataDir = RunExamples.GetDataDir_Charts();
Presentation pres = new Presentation(dataDir+"Test.pptx");
ISlide slide = pres.Slides[0];
//Creating the default chart
IChart chart = slide.Shapes.AddChart(ChartType.LineWithMarkers, 0, 0, 400, 400);
//Getting the default chart data worksheet index
int defaultWorksheetIndex = 0;
//Getting the chart data worksheet
IChartDataWorkbook fact = chart.ChartData.ChartDataWorkbook;
//Delete demo series
chart.ChartData.Series.Clear();
//Add new series
chart.ChartData.Series.Add(fact.GetCell(defaultWorksheetIndex, 1, 1, "Series 1"), chart.Type);
//Set the picture
System.Drawing.Image img = (System.Drawing.Image)new Bitmap(dataDir + "aspose-logo.jpg");
IPPImage imgx1 = pres.Images.AddImage(img);
//Set the picture
System.Drawing.Image img2 = (System.Drawing.Image)new Bitmap(dataDir + "Tulips.jpg");
IPPImage imgx2 = pres.Images.AddImage(img2);
//Take first chart series
IChartSeries series = chart.ChartData.Series[0];
//Add new point (1:3) there.
IChartDataPoint point = series.DataPoints.AddDataPointForLineSeries(fact.GetCell(defaultWorksheetIndex, 1, 1, (double)4.5));
point.Marker.Format.Fill.FillType = FillType.Picture;
point.Marker.Format.Fill.PictureFillFormat.Picture.Image = imgx1;
point = series.DataPoints.AddDataPointForLineSeries(fact.GetCell(defaultWorksheetIndex, 2, 1, (double)2.5));
point.Marker.Format.Fill.FillType = FillType.Picture;
point.Marker.Format.Fill.PictureFillFormat.Picture.Image = imgx2;
point = series.DataPoints.AddDataPointForLineSeries(fact.GetCell(defaultWorksheetIndex, 3, 1, (double)3.5));
point.Marker.Format.Fill.FillType = FillType.Picture;
point.Marker.Format.Fill.PictureFillFormat.Picture.Image = imgx1;
point = series.DataPoints.AddDataPointForLineSeries(fact.GetCell(defaultWorksheetIndex, 4, 1, (double)4.5));
point.Marker.Format.Fill.FillType = FillType.Picture;
point.Marker.Format.Fill.PictureFillFormat.Picture.Image = imgx2;
//Changing the chart series marker
series.Marker.Size = 15;
pres.Save(dataDir+"AsposeScatterChart.pptx", SaveFormat.Pptx);
}
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_Charts();
// Create directory if it is not already present.
bool IsExists = System.IO.Directory.Exists(dataDir);
if (!IsExists)
System.IO.Directory.CreateDirectory(dataDir);
// Creating empty presentation
Presentation pres = new Presentation();
// Creating a clustered column chart
IChart chart = pres.Slides[0].Shapes.AddChart(ChartType.ClusteredColumn, 20, 20, 500, 400);
// Adding ponential trend line for chart series 1
ITrendline tredLinep = chart.ChartData.Series[0].TrendLines.Add(TrendlineType.Exponential);
tredLinep.DisplayEquation = false;
tredLinep.DisplayRSquaredValue = false;
// Adding Linear trend line for chart series 1
ITrendline tredLineLin = chart.ChartData.Series[0].TrendLines.Add(TrendlineType.Linear);
tredLineLin.TrendlineType = TrendlineType.Linear;
tredLineLin.Format.Line.FillFormat.FillType = FillType.Solid;
tredLineLin.Format.Line.FillFormat.SolidFillColor.Color = Color.Red;
// Adding Logarithmic trend line for chart series 2
ITrendline tredLineLog = chart.ChartData.Series[1].TrendLines.Add(TrendlineType.Logarithmic);
tredLineLog.TrendlineType = TrendlineType.Logarithmic;
tredLineLog.AddTextFrameForOverriding("New log trend line");
// Adding MovingAverage trend line for chart series 2
ITrendline tredLineMovAvg = chart.ChartData.Series[1].TrendLines.Add(TrendlineType.MovingAverage);
tredLineMovAvg.TrendlineType = TrendlineType.MovingAverage;
tredLineMovAvg.Period = 3;
tredLineMovAvg.TrendlineName = "New TrendLine Name";
// Adding Polynomial trend line for chart series 3
ITrendline tredLinePol = chart.ChartData.Series[2].TrendLines.Add(TrendlineType.Polynomial);
tredLinePol.TrendlineType = TrendlineType.Polynomial;
tredLinePol.Forward = 1;
tredLinePol.Order = 3;
// Adding Power trend line for chart series 3
ITrendline tredLinePower = chart.ChartData.Series[1].TrendLines.Add(TrendlineType.Power);
tredLinePower.TrendlineType = TrendlineType.Power;
tredLinePower.Backward = 1;
// Saving presentation
pres.Save(dataDir + "ChartTrendLines_out.pptx", SaveFormat.Pptx);
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_Charts();
using (Presentation pres = new Presentation(dataDir + "TestChart.pptx"))
{
ISlide sl = pres.Slides[0];
IChart chart = (IChart)sl.Shapes[0];
foreach (IChartDataPoint dataPoint in chart.ChartData.Series[0].DataPoints)
{
dataPoint.XValue.AsCell.Value = null;
dataPoint.YValue.AsCell.Value = null;
}
chart.ChartData.Series[0].DataPoints.Clear();
pres.Save(dataDir + "ClearSpecificChartSeriesDataPointsData.pptx", SaveFormat.Pptx);
}
//Instantiate Presentation class that represents PPTX file//Instantiate Presentation class that represents PPTX file
Presentation pres = new Presentation();
//Access first slide
ISlide sld = pres.Slides[0];
// Add chart with default data
IChart chart = sld.Shapes.AddChart(ChartType.ClusteredColumn, 0, 0, 500, 500);
//Setting chart Title
//chart.ChartTitle.TextFrameForOverriding.Text = "Sample Title";
chart.ChartTitle.AddTextFrameForOverriding("Sample Title");
chart.ChartTitle.TextFrameForOverriding.TextFrameFormat.CenterText = NullableBool.True;
chart.ChartTitle.Height = 20;
chart.HasTitle = true;
//Set first series to Show Values
chart.ChartData.Series[0].Labels.DefaultDataLabelFormat.ShowValue = true;
//Setting the index of chart data sheet
int defaultWorksheetIndex = 0;
//Getting the chart data worksheet
IChartDataCellFactory fact = chart.ChartData.ChartDataCellFactory;
//Delete default generated series and categories
chart.ChartData.Series.Clear();
chart.ChartData.Categories.Clear();
int s = chart.ChartData.Series.Count;
s = chart.ChartData.Categories.Count;
//Adding new series
chart.ChartData.Series.Add(fact.GetCell(defaultWorksheetIndex, 0, 1, "Series 1"), chart.Type);
chart.ChartData.Series.Add(fact.GetCell(defaultWorksheetIndex, 0, 2, "Series 2"), chart.Type);
//Adding new categories
chart.ChartData.Categories.Add(fact.GetCell(defaultWorksheetIndex, 1, 0, "Caetegoty 1"));
chart.ChartData.Categories.Add(fact.GetCell(defaultWorksheetIndex, 2, 0, "Caetegoty 2"));
chart.ChartData.Categories.Add(fact.GetCell(defaultWorksheetIndex, 3, 0, "Caetegoty 3"));
//Take first chart series
IChartSeries series = chart.ChartData.Series[0];
//Now populating series data
series.DataPoints.AddDataPointForBarSeries(fact.GetCell(defaultWorksheetIndex, 1, 1, 20));
series.DataPoints.AddDataPointForBarSeries(fact.GetCell(defaultWorksheetIndex, 2, 1, 50));
series.DataPoints.AddDataPointForBarSeries(fact.GetCell(defaultWorksheetIndex, 3, 1, 30));
//Setting fill color for series
series.Format.Fill.FillType = FillType.Solid;
series.Format.Fill.SolidFillColor.Color = Color.Red;
//Take second chart series
series = chart.ChartData.Series[1];
//Now populating series data
series.DataPoints.AddDataPointForBarSeries(fact.GetCell(defaultWorksheetIndex, 1, 2, 30));
series.DataPoints.AddDataPointForBarSeries(fact.GetCell(defaultWorksheetIndex, 2, 2, 10));
series.DataPoints.AddDataPointForBarSeries(fact.GetCell(defaultWorksheetIndex, 3, 2, 60));
//Setting fill color for series
series.Format.Fill.FillType = FillType.Solid;
series.Format.Fill.SolidFillColor.Color = Color.Green;
//create custom labels for each of categories for new series
//first label will be show Category name
IDataLabel lbl = series.DataPoints[0].Label;
lbl.DataLabelFormat.ShowCategoryName = true;
lbl = series.DataPoints[1].Label;
lbl.DataLabelFormat.ShowSeriesName = true;
//Show value for third label
lbl = series.DataPoints[2].Label;
lbl.DataLabelFormat.ShowValue = true;
lbl.DataLabelFormat.ShowSeriesName = true;
lbl.DataLabelFormat.Separator = "/";
//Save presentation with chart
pres.Save("AsposeChart.pptx", SaveFormat.Pptx);
//Create empty presentation
using (Presentation pres = new Presentation())
{
//Accessing first slide
ISlide slide = pres.Slides[0];
//Addding default chart
IChart ppChart = slide.Shapes.AddChart(ChartType.ClusteredColumn3D, 20F, 30F, 400F, 300F);
//Getting Chart data
IChartData chartData = ppChart.ChartData;
//Removing Extra default series
chartData.Series.RemoveAt(1);
chartData.Series.RemoveAt(1);
//Modifying chart categories names
chartData.Categories[0].AsCell.Value = "Bikes";
chartData.Categories[1].AsCell.Value = "Accessories";
chartData.Categories[2].AsCell.Value = "Repairs";
chartData.Categories[3].AsCell.Value = "Clothing";
//Setting the index of chart data sheet
int defaultWorksheetIndex = 0;
//Getting the chart data worksheet
IChartDataCellFactory fact = ppChart.ChartData.ChartDataCellFactory;
//Modifying chart series values for first category
chartData.Series[0].DataPoints.AddDataPointForBarSeries(fact.GetCell(defaultWorksheetIndex, 1, 1, 1000));
chartData.Series[0].DataPoints.AddDataPointForBarSeries(fact.GetCell(defaultWorksheetIndex, 2, 1, 2500));
chartData.Series[0].DataPoints.AddDataPointForBarSeries(fact.GetCell(defaultWorksheetIndex, 3, 1, 4000));
chartData.Series[0].DataPoints.AddDataPointForBarSeries(fact.GetCell(defaultWorksheetIndex, 4, 1, 3000));
//Setting Chart title
ppChart.HasTitle = true;
ppChart.ChartTitle.AddTextFrameForOverriding("2007 Sales");
IPortionFormat format = ppChart.ChartTitle.TextFrameForOverriding.Paragraphs[0].Portions[0].PortionFormat;
format.FontItalic = NullableBool.True;
format.FontHeight = 18;
format.FillFormat.FillType = FillType.Solid;
format.FillFormat.SolidFillColor.Color = Color.Black;
////Setting Axis values
ppChart.Axes.VerticalAxis.IsAutomaticMaxValue = false;
ppChart.Axes.VerticalAxis.IsAutomaticMinValue = false;
ppChart.Axes.VerticalAxis.IsAutomaticMajorUnit = false;
ppChart.Axes.VerticalAxis.IsAutomaticMinorUnit = false;
ppChart.Axes.VerticalAxis.MaxValue = 4000.0F;
ppChart.Axes.VerticalAxis.MinValue = 0.0F;
ppChart.Axes.VerticalAxis.MajorUnit = 2000.0F;
ppChart.Axes.VerticalAxis.MinorUnit = 1000.0F;
ppChart.Axes.VerticalAxis.TickLabelPosition = TickLabelPositionType.NextTo;
//Setting Chart rotation
ppChart.Rotation3D.RotationX = 15;
ppChart.Rotation3D.RotationY = 20;
//Saving Presentation
pres.Save("c:\\data\\AsposeSampleChart.pptx", SaveFormat.Pptx);
}
//Instantiate PresentationEx class that represents PPTX file
using (PresentationEx pres = new PresentationEx())
{
//Access first slide
SlideEx sld = pres.Slides[0];
// Add chart with default data
ChartEx chart = sld.Shapes.AddChart(ChartTypeEx.ClusteredColumn, 0, 0, 500, 500);
//Setting chart Title
chart.ChartTitle.Text.Text = "Sample Title";
chart.ChartTitle.Text.CenterText = true;
chart.ChartTitle.Height = 20;
chart.HasTitle = true;
//Set first series to Show Values
chart.ChartData.Series[0].Labels.ShowValue = true;
//Setting the index of chart data sheet
int defaultWorksheetIndex = 0;
//Getting the chart data worksheet
ChartDataCellFactory fact = chart.ChartData.ChartDataCellFactory;
//Delete default generated series and categories
chart.ChartData.Series.Clear();
chart.ChartData.Categories.Clear();
int s = chart.ChartData.Series.Count;
s = chart.ChartData.Categories.Count;
//Adding new series
chart.ChartData.Series.Add(fact.GetCell(defaultWorksheetIndex, 0, 1, "Series 1"), chart.Type);
chart.ChartData.Series.Add(fact.GetCell(defaultWorksheetIndex, 0, 2, "Series 2"), chart.Type);
//Adding new categories
chart.ChartData.Categories.Add(fact.GetCell(defaultWorksheetIndex, 1, 0, "Caetegoty 1"));
chart.ChartData.Categories.Add(fact.GetCell(defaultWorksheetIndex, 2, 0, "Caetegoty 2"));
chart.ChartData.Categories.Add(fact.GetCell(defaultWorksheetIndex, 3, 0, "Caetegoty 3"));
//Take first chart series
ChartSeriesEx series = chart.ChartData.Series[0];
//Now populating series data
series.Values.Add(fact.GetCell(defaultWorksheetIndex, 1, 1, 20));
series.Values.Add(fact.GetCell(defaultWorksheetIndex, 2, 1, 50));
series.Values.Add(fact.GetCell(defaultWorksheetIndex, 3, 1, 30));
//Setting fill color for series
series.Format.Fill.FillType = FillTypeEx.Solid;
series.Format.Fill.SolidFillColor.Color = Color.Red;
//Take second chart series
series = chart.ChartData.Series[1];
//Now populating series data
series.Values.Add(fact.GetCell(defaultWorksheetIndex, 1, 2, 30));
series.Values.Add(fact.GetCell(defaultWorksheetIndex, 2, 2, 10));
series.Values.Add(fact.GetCell(defaultWorksheetIndex, 3, 2, 60));
//Setting fill color for series
series.Format.Fill.FillType = FillTypeEx.Solid;
series.Format.Fill.SolidFillColor.Color = Color.Green;
//create custom labels for each of categories for new series
//first label will be show Category name
DataLabelEx lbl = new DataLabelEx(series);
lbl.ShowCategoryName = true;
lbl.Id = 0;
series.Labels.Add(lbl);
//Show series name for second label
lbl = new DataLabelEx(series);
lbl.ShowSeriesName = true;
lbl.Id = 1;
series.Labels.Add(lbl);
//Show value for third label
lbl = new DataLabelEx(series);
lbl.ShowValue = true;
lbl.ShowSeriesName = true;
lbl.Separator = "/";
lbl.Id = 2;
series.Labels.Add(lbl);
//Show value and custom text
lbl = new DataLabelEx(series);
lbl.TextFrame.Text = "My text";
lbl.Id = 3;
series.Labels.Add(lbl);
//Save presentation with chart
pres.Write(@"D:\AsposeChart.pptx");
}
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_Charts();
using (Presentation pres = new Presentation(dataDir + "presentation.pptx"))
{
string externalWbPath = dataDir + "externalWorkbook1.xlsx";
IChart chart = pres.Slides[0].Shapes.AddChart(ChartType.Pie, 50, 50, 400, 600);
if (File.Exists(externalWbPath))
File.Delete(externalWbPath);
using (FileStream fileStream = new FileStream(externalWbPath, FileMode.CreateNew))
{
byte[] worbookData = chart.ChartData.ReadWorkbookStream().ToArray();
fileStream.Write(worbookData, 0, worbookData.Length);
}
chart.ChartData.SetExternalWorkbook(externalWbPath);
pres.Save(dataDir + "Presentation_with_externalWbPath.pptx", SaveFormat.Pptx);
}
Presentation pres = new Presentation();
ISlide slide = pres.Slides[0];
//Creating the default chart
IChart chart = slide.Shapes.AddChart(ChartType.ScatterWithSmoothLines, 0, 0, 400, 400);
//Getting the default chart data worksheet index
int defaultWorksheetIndex = 0;
//Accessing the chart data worksheet
IChartDataCellFactory fact = chart.ChartData.ChartDataCellFactory;
//Delete demo series
chart.ChartData.Series.Clear();
//Add new series
chart.ChartData.Series.Add(fact.GetCell(defaultWorksheetIndex, 1, 1, "Series 1"), chart.Type);
chart.ChartData.Series.Add(fact.GetCell(defaultWorksheetIndex, 1, 3, "Series 2"), chart.Type);
//Take first chart series
IChartSeries series = chart.ChartData.Series[0];
//Add new point (1:3) there.
series.DataPoints.AddDataPointForScatterSeries(fact.GetCell(defaultWorksheetIndex, 2, 1, 1), fact.GetCell(defaultWorksheetIndex, 2, 2, 3));
//Add new point (2:10)
series.DataPoints.AddDataPointForScatterSeries(fact.GetCell(defaultWorksheetIndex, 3, 1, 2), fact.GetCell(defaultWorksheetIndex, 3, 2, 10));
//Edit the type of series
series.Type = ChartType.ScatterWithStraightLinesAndMarkers;
//Changing the chart series marker
series.Marker.Size = 10;
series.Marker.Symbol = MarkerStyleType.Star;
//Take second chart series
series = chart.ChartData.Series[1];
//Add new point (5:2) there.
series.DataPoints.AddDataPointForScatterSeries(fact.GetCell(defaultWorksheetIndex, 2, 3, 5), fact.GetCell(defaultWorksheetIndex, 2, 4, 2));
//Add new point (3:1)
series.DataPoints.AddDataPointForScatterSeries(fact.GetCell(defaultWorksheetIndex, 3, 3, 3), fact.GetCell(defaultWorksheetIndex, 3, 4, 1));
//Add new point (2:2)
series.DataPoints.AddDataPointForScatterSeries(fact.GetCell(defaultWorksheetIndex, 4, 3, 2), fact.GetCell(defaultWorksheetIndex, 4, 4, 2));
//Add new point (5:1)
series.DataPoints.AddDataPointForScatterSeries(fact.GetCell(defaultWorksheetIndex, 5, 3, 5), fact.GetCell(defaultWorksheetIndex, 5, 4, 1));
//Changing the chart series marker
series.Marker.Size = 10;
series.Marker.Symbol = MarkerStyleType.Circle;
pres.Save("AsposeScatterChart.pptx", SaveFormat.Pptx);
using (PresentationEx pres = new PresentationEx())
{
SlideEx slide = pres.Slides[0];
//Creating the default chart
ChartEx chart = slide.Shapes.AddChart(ChartTypeEx.ScatterWithSmoothLines, 0, 0, 400, 400);
//Getting the default chart data worksheet index
int defaultWorksheetIndex = 0;
//Accessing the chart data worksheet
ChartDataCellFactory fact = chart.ChartData.ChartDataCellFactory;
//Delete demo series
chart.ChartData.Series.Clear();
//Add new series
chart.ChartData.Series.Add(fact.GetCell(defaultWorksheetIndex, 1, 1, "Series 1"), chart.Type);
chart.ChartData.Series.Add(fact.GetCell(defaultWorksheetIndex, 1, 3, "Series 2"), chart.Type);
//Take first chart series
ChartSeriesEx series = chart.ChartData.Series[0];
//Add new point (1:3) there.
series.XValues.Add(fact.GetCell(defaultWorksheetIndex, 2, 1, 1));
series.YValues.Add(fact.GetCell(defaultWorksheetIndex, 2, 2, 3));
//Add new point (2:10)
series.XValues.Add(fact.GetCell(defaultWorksheetIndex, 3, 1, 2));
series.YValues.Add(fact.GetCell(defaultWorksheetIndex, 3, 2, 10));
//Edit the type of series
series.Type = ChartTypeEx.ScatterWithStraightLinesAndMarkers;
//Changing the chart series marker
series.MarkerSize = 10;
series.MarkerSymbol = MarkerStyleTypeEx.Star;
//Take second chart series
series = chart.ChartData.Series[1];
//Add new point (5:2) there.
series.XValues.Add(fact.GetCell(defaultWorksheetIndex, 2, 3, 5));
series.YValues.Add(fact.GetCell(defaultWorksheetIndex, 2, 4, 2));
//Add new point (3:1)
series.XValues.Add(fact.GetCell(defaultWorksheetIndex, 3, 3, 3));
series.YValues.Add(fact.GetCell(defaultWorksheetIndex, 3, 4, 1));
//Add new point (2:2)
series.XValues.Add(fact.GetCell(defaultWorksheetIndex, 4, 3, 2));
series.YValues.Add(fact.GetCell(defaultWorksheetIndex, 4, 4, 2));
//Add new point (5:1)
series.XValues.Add(fact.GetCell(defaultWorksheetIndex, 5, 3, 5));
series.YValues.Add(fact.GetCell(defaultWorksheetIndex, 5, 4, 1));
//Changing the chart series marker
series.MarkerSize = 10;
series.MarkerSymbol = MarkerStyleTypeEx.Circle;
pres.Write("D:\\AsposeSeriesChart.pptx");
}
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_Charts();
using (Presentation pres = new Presentation(dataDir + "pres.pptx"))
{
ISlide slide = pres.Slides[1];
IChart chart = (IChart)slide.Shapes[0];
ChartDataSourceType sourceType = chart.ChartData.DataSourceType;
if (sourceType == ChartDataSourceType.ExternalWorkbook)
{
string path = chart.ChartData.ExternalWorkbookPath;
}
// Saving presentation
pres.Save(dataDir + "Result.pptx", SaveFormat.Pptx);
}
}
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_Charts();
using (Presentation pres = new Presentation())
{
ISlide slide = pres.Slides[0];
IChart chart = slide.Shapes.AddChart(ChartType.LineWithMarkers, 10, 10, 400, 400);
chart.ChartData.Series.Clear();
chart.ChartData.Categories.Clear();
IChartDataWorkbook fact = chart.ChartData.ChartDataWorkbook;
chart.ChartData.Series.Add(fact.GetCell(0, 0, 1, "Series 1"), chart.Type);
IChartSeries series = chart.ChartData.Series[0];
chart.ChartData.Categories.Add(fact.GetCell(0, 1, 0, "C1"));
series.DataPoints.AddDataPointForLineSeries(fact.GetCell(0, 1, 1, 24));
chart.ChartData.Categories.Add(fact.GetCell(0, 2, 0, "C2"));
series.DataPoints.AddDataPointForLineSeries(fact.GetCell(0, 2, 1, 23));
chart.ChartData.Categories.Add(fact.GetCell(0, 3, 0, "C3"));
series.DataPoints.AddDataPointForLineSeries(fact.GetCell(0, 3, 1, -10));
chart.ChartData.Categories.Add(fact.GetCell(0, 4, 0, "C4"));
series.DataPoints.AddDataPointForLineSeries(fact.GetCell(0, 4, 1, null));
chart.ChartData.Series.Add(fact.GetCell(0, 0, 2, "Series 2"), chart.Type);
//Take second chart series
IChartSeries series2 = chart.ChartData.Series[1];
//Now populating series data
series2.DataPoints.AddDataPointForLineSeries(fact.GetCell(0, 1, 2, 30));
series2.DataPoints.AddDataPointForLineSeries(fact.GetCell(0, 2, 2, 10));
series2.DataPoints.AddDataPointForLineSeries(fact.GetCell(0, 3, 2, 60));
series2.DataPoints.AddDataPointForLineSeries(fact.GetCell(0, 4, 2, 40));
chart.HasLegend = true;
chart.Legend.Overlay = false;
pres.Save(dataDir + "DefaultMarkersInChart.pptx", SaveFormat.Pptx);
}
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_Charts();
using (Presentation presentation = new Presentation())
{
IChart chart = presentation.Slides[0].Shapes.AddChart(ChartType.Pie, 50, 50, 500, 400);
chart.ChartData.Series[0].Labels.DefaultDataLabelFormat.ShowValue = true;
chart.ChartData.Series[0].Labels.DefaultDataLabelFormat.ShowLabelAsDataCallout = true;
chart.ChartData.Series[0].Labels[2].DataLabelFormat.ShowLabelAsDataCallout = false;
presentation.Save(dataDir + "DisplayChartLabels_out.pptx", SaveFormat.Pptx);
}
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_Charts();
// Create an instance of Presentation class
Presentation presentation = new Presentation();
ISlide slide = presentation.Slides[0];
IChart chart = slide.Shapes.AddChart(ChartType.StackedColumn, 20, 20, 400, 400);
IChartSeries series = chart.ChartData.Series[0];
IChartCategory cat;
double[] total_for_Cat = new double[chart.ChartData.Categories.Count];
for (int k = 0; k < chart.ChartData.Categories.Count; k++)
{
cat = chart.ChartData.Categories[k];
for (int i = 0; i < chart.ChartData.Series.Count; i++)
{
total_for_Cat[k] = total_for_Cat[k] + Convert.ToDouble(chart.ChartData.Series[i].DataPoints[k].Value.Data);
}
}
double dataPontPercent = 0f;
for (int x = 0; x < chart.ChartData.Series.Count; x++)
{
series = chart.ChartData.Series[x];
series.Labels.DefaultDataLabelFormat.ShowLegendKey = false;
for (int j = 0; j < series.DataPoints.Count; j++)
{
IDataLabel lbl = series.DataPoints[j].Label;
dataPontPercent = (Convert.ToDouble(series.DataPoints[j].Value.Data) / total_for_Cat[j]) * 100;
IPortion port = new Portion();
port.Text = String.Format("{0:F2} %", dataPontPercent);
port.PortionFormat.FontHeight = 8f;
lbl.TextFrameForOverriding.Text = "";
IParagraph para = lbl.TextFrameForOverriding.Paragraphs[0];
para.Portions.Add(port);
lbl.DataLabelFormat.ShowSeriesName = false;
lbl.DataLabelFormat.ShowPercentage = false;
lbl.DataLabelFormat.ShowLegendKey = false;
lbl.DataLabelFormat.ShowCategoryName = false;
lbl.DataLabelFormat.ShowBubbleSize = false;
}
}
// Save presentation with chart
presentation.Save(dataDir + "DisplayPercentageAsLabels_out.pptx", SaveFormat.Pptx);
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_Charts();
// Create an instance of Presentation class
Presentation presentation = new Presentation();
IChart chart = presentation.Slides[0].Shapes.AddChart(ChartType.Doughnut, 50, 50, 400, 400);
chart.ChartData.SeriesGroups[0].DoughnutHoleSize = 90;
// Write presentation to disk
presentation.Save(dataDir + "DoughnutHoleSize_out.pptx", SaveFormat.Pptx);
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_Charts();
using (Presentation pres = new Presentation(dataDir + "presentation.pptx"))
{
IChart chart = pres.Slides[0].Shapes[0] as IChart;
ChartData chartData = (ChartData)chart.ChartData;
chartData.Series[0].DataPoints[0].Value.AsCell.Value = 100;
pres.Save(dataDir + "presentation_out.pptx", SaveFormat.Pptx);
}
static void AddExcelChartInPresentation(Presentation pres, ISlide sld, Stream wbStream, Bitmap imgChart)
{
float oleWidth = pres.SlideSize.Size.Width;
float oleHeight = pres.SlideSize.Size.Height;
int x = 0;
byte[] chartOleData = new byte[wbStream.Length];
wbStream.Position = 0;
wbStream.Read(chartOleData, 0, chartOleData.Length);
IOleObjectFrame oof = null;
oof = sld.Shapes.AddOleObjectFrame(x, 0, oleWidth, oleHeight, "Excel.Sheet.8", chartOleData);
oof.SubstitutePictureFormat.Picture.Image = pres.Images.AddImage((System.Drawing.Image)imgChart);
}
static int AddExcelChartInWorkbook(Aspose.Cells.Workbook wb, int chartRows, int chartCols)
{
//Array of cell names
string[] cellsName = new string[]
{
"A1", "A2", "A3", "A4",
"B1", "B2", "B3", "B4",
"C1", "C2", "C3", "C4",
"D1", "D2", "D3", "D4",
"E1", "E2", "E3", "E4"
};
//Array of cell data
int[] cellsValue = new int[]
{
67,86,68,91,
44,64,89,48,
46,97,78,60,
43,29,69,26,
24,40,38,25
};
//Add a new worksheet to populate cells with data
int dataSheetIdx = wb.Worksheets.Add();
Aspose.Cells.Worksheet dataSheet = wb.Worksheets[dataSheetIdx];
string sheetName = "DataSheet";
dataSheet.Name = sheetName;
//Populate DataSheet with data
for (int i = 0; i < cellsName.Length; i++)
{
string cellName = cellsName[i];
int cellValue = cellsValue[i];
dataSheet.Cells[cellName].PutValue(cellValue);
}
//Add a chart sheet
int chartSheetIdx = wb.Worksheets.Add(Aspose.Cells.SheetType.Chart);
Aspose.Cells.Worksheet chartSheet = wb.Worksheets[chartSheetIdx];
chartSheet.Name = "ChartSheet";
//Add a chart in ChartSheet with data series from DataSheet
int chartIdx = chartSheet.Charts.Add(Aspose.Cells.Charts.ChartType.Column, 0, chartRows, 0, chartCols);
Aspose.Cells.Charts.Chart chart = chartSheet.Charts[chartIdx];
chart.NSeries.Add(sheetName + "!A1:E1", false);
chart.NSeries.Add(sheetName + "!A2:E2", false);
chart.NSeries.Add(sheetName + "!A3:E3", false);
chart.NSeries.Add(sheetName + "!A4:E4", false);
//Set ChartSheet an active sheet
wb.Worksheets.ActiveSheetIndex = chartSheetIdx;
return chartSheetIdx;
}
//Step - 1: Create an excel chart using Aspose.Cells
//--------------------------------------------------
//Create a workbook
Aspose.Cells.Workbook wb = new Aspose.Cells.Workbook();
//Add an excel chart
int chartRows = 55;
int chartCols = 25;
int chartSheetIndex = AddExcelChartInWorkbook(wb, chartRows, chartCols);
//Step - 2: Set the OLE size of the chart. using Aspose.Cells
//-----------------------------------------------------------
wb.Worksheets.SetOleSize(0, chartRows, 0, chartCols);
//Step - 3: Get the image of the chart with Aspose.Cells
//-----------------------------------------------------------
Bitmap imgChart = wb.Worksheets[chartSheetIndex].Charts[0].ToImage();
//Save the workbook to stream
MemoryStream wbStream = wb.SaveToStream();
//Step - 4 AND 5
//-----------------------------------------------------------
//Step - 4: Embed the chart as an OLE object inside .ppt presentation using Aspose.Slides
//-----------------------------------------------------------
//Step - 5: Replace the object changed image with the image obtained in step 3 to cater Object Changed Issue
//-----------------------------------------------------------
//Create a presentation
Presentation pres = new Presentation();
ISlide sld = pres.Slides[0];
//Add the workbook on slide
AddExcelChartInPresentation(pres, sld, wbStream, imgChart);
//Step - 6: Write the output presentation on disk
//-----------------------------------------------------------
pres.Save("OutputChart.pptx", Aspose.Slides.Export.SaveFormat.Pptx);
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_Charts();
// Instantiate Presentation class that represents PPTX file// Instantiate Presentation class that represents PPTX file
Presentation pres = new Presentation(dataDir + "ExistingChart.pptx");
// Access first slideMarker
ISlide sld = pres.Slides[0];
// Add chart with default data
IChart chart = (IChart)sld.Shapes[0];
// Setting the index of chart data sheet
int defaultWorksheetIndex = 0;
// Getting the chart data worksheet
IChartDataWorkbook fact = chart.ChartData.ChartDataWorkbook;
// Changing chart Category Name
fact.GetCell(defaultWorksheetIndex, 1, 0, "Modified Category 1");
fact.GetCell(defaultWorksheetIndex, 2, 0, "Modified Category 2");
// Take first chart series
IChartSeries series = chart.ChartData.Series[0];
// Now updating series data
fact.GetCell(defaultWorksheetIndex, 0, 1, "New_Series1");// Modifying series name
series.DataPoints[0].Value.Data = 90;
series.DataPoints[1].Value.Data = 123;
series.DataPoints[2].Value.Data = 44;
// Take Second chart series
series = chart.ChartData.Series[1];
// Now updating series data
fact.GetCell(defaultWorksheetIndex, 0, 2, "New_Series2");// Modifying series name
series.DataPoints[0].Value.Data = 23;
series.DataPoints[1].Value.Data = 67;
series.DataPoints[2].Value.Data = 99;
// Now, Adding a new series
chart.ChartData.Series.Add(fact.GetCell(defaultWorksheetIndex, 0, 3, "Series 3"), chart.Type);
// Take 3rd chart series
series = chart.ChartData.Series[2];
// Now populating series data
series.DataPoints.AddDataPointForBarSeries(fact.GetCell(defaultWorksheetIndex, 1, 3, 20));
series.DataPoints.AddDataPointForBarSeries(fact.GetCell(defaultWorksheetIndex, 2, 3, 50));
series.DataPoints.AddDataPointForBarSeries(fact.GetCell(defaultWorksheetIndex, 3, 3, 30));
chart.Type = ChartType.ClusteredCylinder;
// Save presentation with chart
pres.Save(dataDir + "AsposeChartModified_out.pptx", SaveFormat.Pptx);
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_Charts();
using (Presentation pres = new Presentation(dataDir+"test.pptx"))
{
IChart chart = pres.Slides[0].Shapes.AddChart(Aspose.Slides.Charts.ChartType.ClusteredColumn, 50, 50, 600, 400);
chart.Legend.TextFormat.PortionFormat.FontHeight = 20;
chart.Axes.VerticalAxis.IsAutomaticMinValue = false;
chart.Axes.VerticalAxis.MinValue = -5;
chart.Axes.VerticalAxis.IsAutomaticMaxValue = false;
chart.Axes.VerticalAxis.MaxValue = 10;
pres.Save(dataDir+"output.pptx", SaveFormat.Pptx);
}
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_Charts();
using (Presentation pres = new Presentation())
{
IChart chart = pres.Slides[0].Shapes.AddChart(ChartType.ClusteredColumn, 100, 100, 500, 400);
chart.TextFormat.PortionFormat.FontHeight = 20;
chart.ChartData.Series[0].Labels.DefaultDataLabelFormat.ShowValue = true;
pres.Save(dataDir + "FontPropertiesForChart.pptx", SaveFormat.Pptx);
}
string dataDir = RunExamples.GetDataDir_Charts();
using (Presentation pres = new Presentation(dataDir+"test.pptx"))
{
IChart chart = pres.Slides[0].Shapes.AddChart(ChartType.ClusteredColumn, 50, 50, 600, 400);
IChartTextFormat tf = chart.Legend.Entries[1].TextFormat;
tf.PortionFormat.FontBold = NullableBool.True;
tf.PortionFormat.FontHeight = 20;
tf.PortionFormat.FontItalic = NullableBool.True;
tf.PortionFormat.FillFormat.FillType = FillType.Solid; ;
tf.PortionFormat.FillFormat.SolidFillColor.Color = Color.Blue;
pres.Save(dataDir+"output.pptx", SaveFormat.Pptx);
}
public static void Run()
{
string dataDir = RunExamples.GetDataDir_Charts();
using (Presentation pres = new Presentation(dataDir+"test.pptx"))
{
IChart chart = pres.Slides[0].Shapes.AddChart(ChartType.Funnel, 50, 50, 500, 400);
chart.ChartData.Categories.Clear();
chart.ChartData.Series.Clear();
IChartDataWorkbook wb = chart.ChartData.ChartDataWorkbook;
wb.Clear(0);
chart.ChartData.Categories.Add(wb.GetCell(0, "A1", "Category 1"));
chart.ChartData.Categories.Add(wb.GetCell(0, "A2", "Category 2"));
chart.ChartData.Categories.Add(wb.GetCell(0, "A3", "Category 3"));
chart.ChartData.Categories.Add(wb.GetCell(0, "A4", "Category 4"));
chart.ChartData.Categories.Add(wb.GetCell(0, "A5", "Category 5"));
chart.ChartData.Categories.Add(wb.GetCell(0, "A6", "Category 6"));
IChartSeries series = chart.ChartData.Series.Add(ChartType.Funnel);
series.DataPoints.AddDataPointForFunnelSeries(wb.GetCell(0, "B1", 50));
series.DataPoints.AddDataPointForFunnelSeries(wb.GetCell(0, "B2", 100));
series.DataPoints.AddDataPointForFunnelSeries(wb.GetCell(0, "B3", 200));
series.DataPoints.AddDataPointForFunnelSeries(wb.GetCell(0, "B4", 300));
series.DataPoints.AddDataPointForFunnelSeries(wb.GetCell(0, "B5", 400));
series.DataPoints.AddDataPointForFunnelSeries(wb.GetCell(0, "B6", 500));
pres.Save(dataDir+"Funnel.pptx", SaveFormat.Pptx);
}
}
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_Charts();
using (Presentation pres = new Presentation())
{
IChart chart = pres.Slides[0].Shapes.AddChart(ChartType.ClusteredColumn, 50, 50, 500, 400);
foreach (IChartSeries series in chart.ChartData.Series)
{
series.Labels.DefaultDataLabelFormat.Position = LegendDataLabelPosition.OutsideEnd;
series.Labels.DefaultDataLabelFormat.ShowValue = true;
}
chart.ValidateChartLayout();
foreach (IChartSeries series in chart.ChartData.Series)
{
foreach (IChartDataPoint point in series.DataPoints)
{
if (point.Value.ToDouble() > 4)
{
float x = point.Label.ActualX;
float y = point.Label.ActualY;
float w = point.Label.ActualWidth;
float h = point.Label.ActualHeight;
IAutoShape shape = chart.UserShapes.Shapes.AddAutoShape(ShapeType.Ellipse, x, y, w, h);
shape.FillFormat.FillType = FillType.Solid;
shape.FillFormat.SolidFillColor.Color = Color.FromArgb(100, 0, 255, 0);
}
}
}
pres.Save(dataDir + "GetActualPositionOFChartDatalabel", SaveFormat.Pptx);
}
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_Charts();
using (Presentation pres = new Presentation(dataDir+"test.pptx"))
{
IChart chart = pres.Slides[0].Shapes.AddChart(ChartType.ClusteredColumn, 50, 50, 600, 400);
Image img = chart.GetThumbnail();
img.Save(dataDir+"image.png", ImageFormat.Png);
}
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_Charts();
using (Presentation pres = new Presentation())
{
Chart chart = (Chart)pres.Slides[0].Shapes.AddChart(ChartType.Area, 100, 100, 500, 350);
chart.ValidateChartLayout();
double maxValue = chart.Axes.VerticalAxis.ActualMaxValue;
double minValue = chart.Axes.VerticalAxis.ActualMinValue;
double majorUnit = chart.Axes.HorizontalAxis.ActualMajorUnit;
double minorUnit = chart.Axes.HorizontalAxis.ActualMinorUnit;
// Saving presentation
pres.Save(dataDir + "ErrorBars_out.pptx", SaveFormat.Pptx);
}
}
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_Charts();
using (Presentation pres = new Presentation(dataDir+"test.Pptx"))
{
Chart chart = (Chart)pres.Slides[0].Shapes.AddChart(ChartType.ClusteredColumn, 100, 100, 500, 350);
chart.ValidateChartLayout();
double x = chart.PlotArea.ActualX;
double y = chart.PlotArea.ActualY;
double w = chart.PlotArea.ActualWidth;
double h = chart.PlotArea.ActualHeight;
// Save presentation with chart
pres.Save(dataDir + "Chart_out.pptx", SaveFormat.Pptx);
}
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_Charts();
using (Presentation pres = new Presentation())
{
ISlide slide = pres.Slides[0];
IChart chart = slide.Shapes.AddChart(ChartType.LineWithMarkers, 140, 118, 320, 370);
//Hiding chart Title
chart.HasTitle = false;
///Hiding Values axis
chart.Axes.VerticalAxis.IsVisible = false;
//Category Axis visibility
chart.Axes.HorizontalAxis.IsVisible = false;
//Hiding Legend
chart.HasLegend = false;
//Hiding MajorGridLines
chart.Axes.HorizontalAxis.MajorGridLinesFormat.Line.FillFormat.FillType = FillType.NoFill;
for (int i = 0; i < chart.ChartData.Series.Count; i++)
{
chart.ChartData.Series.RemoveAt(i);
}
IChartSeries series = chart.ChartData.Series[0];
series.Marker.Symbol = MarkerStyleType.Circle;
series.Labels.DefaultDataLabelFormat.ShowValue = true;
series.Labels.DefaultDataLabelFormat.Position = LegendDataLabelPosition.Top;
series.Marker.Size = 15;
//Setting series line color
series.Format.Line.FillFormat.FillType = FillType.Solid;
series.Format.Line.FillFormat.SolidFillColor.Color = Color.Purple;
series.Format.Line.DashStyle = LineDashStyle.Solid;
pres.Save(dataDir + "HideInformationFromChart.pptx", SaveFormat.Pptx);
}
public static void Run()
{
string dataDir = RunExamples.GetDataDir_Charts();
using (Presentation pres = new Presentation(dataDir+"test.pptx"))
{
IChart chart = pres.Slides[0].Shapes.AddChart(ChartType.Histogram, 50, 50, 500, 400);
chart.ChartData.Categories.Clear();
chart.ChartData.Series.Clear();
IChartDataWorkbook wb = chart.ChartData.ChartDataWorkbook;
wb.Clear(0);
IChartSeries series = chart.ChartData.Series.Add(ChartType.Histogram);
series.DataPoints.AddDataPointForHistogramSeries(wb.GetCell(0, "A1", 15));
series.DataPoints.AddDataPointForHistogramSeries(wb.GetCell(0, "A2", -41));
series.DataPoints.AddDataPointForHistogramSeries(wb.GetCell(0, "A3", 16));
series.DataPoints.AddDataPointForHistogramSeries(wb.GetCell(0, "A4", 10));
series.DataPoints.AddDataPointForHistogramSeries(wb.GetCell(0, "A5", -23));
series.DataPoints.AddDataPointForHistogramSeries(wb.GetCell(0, "A6", 16));
chart.Axes.HorizontalAxis.AggregationType = AxisAggregationType.Automatic;
pres.Save(dataDir+"Histogram.pptx", SaveFormat.Pptx);
}
}
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_Charts();
// Creating empty presentation
using (Presentation pres = new Presentation())
{
Chart chart = (Chart)pres.Slides[0].Shapes.AddChart(ChartType.ClusteredColumn, 100, 100, 500, 350);
chart.ValidateChartLayout();
double x = chart.PlotArea.ActualX;
double y = chart.PlotArea.ActualY;
double w = chart.PlotArea.ActualWidth;
double h = chart.PlotArea.ActualHeight;
}
}
string dataDir = RunExamples.GetDataDir_Charts();
using (Presentation pres = new Presentation())
{
IChart chart = pres.Slides[0].Shapes.AddChart(ChartType.ClusteredColumn, 50, 50, 600, 400, true);
IChartSeriesCollection series = chart.ChartData.Series;
chart.ChartData.Series.Clear();
series.Add(chart.ChartData.ChartDataWorkbook.GetCell(0, "B1"), chart.Type);
series[0].DataPoints.AddDataPointForBarSeries(chart.ChartData.ChartDataWorkbook.GetCell(0, "B2", -5));
series[0].DataPoints.AddDataPointForBarSeries(chart.ChartData.ChartDataWorkbook.GetCell(0, "B3", 3));
series[0].DataPoints.AddDataPointForBarSeries(chart.ChartData.ChartDataWorkbook.GetCell(0, "B4", -2));
series[0].DataPoints.AddDataPointForBarSeries(chart.ChartData.ChartDataWorkbook.GetCell(0, "B5", 1));
series[0].InvertIfNegative = false;
series[0].DataPoints[2].InvertIfNegative = true;
pres.Save(dataDir+ "InvertIfNegativeForIndividualSeries.pptx", SaveFormat.Pptx);
}
}
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_Charts();
// Create an instance of Presentation class
Presentation presentation = new Presentation();
// Access first slide
ISlide slide = presentation.Slides[0];
// Add chart with default data
IChart chart = slide.Shapes.AddChart(ChartType.StackedColumn3D, 0, 0, 500, 500);
// Setting the index of chart data sheet
int defaultWorksheetIndex = 0;
// Getting the chart data worksheet
IChartDataWorkbook fact = chart.ChartData.ChartDataWorkbook;
// Add series
chart.ChartData.Series.Add(fact.GetCell(defaultWorksheetIndex, 0, 1, "Series 1"), chart.Type);
chart.ChartData.Series.Add(fact.GetCell(defaultWorksheetIndex, 0, 2, "Series 2"), chart.Type);
// Add Catrgories
chart.ChartData.Categories.Add(fact.GetCell(defaultWorksheetIndex, 1, 0, "Caetegoty 1"));
chart.ChartData.Categories.Add(fact.GetCell(defaultWorksheetIndex, 2, 0, "Caetegoty 2"));
chart.ChartData.Categories.Add(fact.GetCell(defaultWorksheetIndex, 3, 0, "Caetegoty 3"));
// Set Rotation3D properties
chart.Rotation3D.RightAngleAxes = true;
chart.Rotation3D.RotationX = 40;
chart.Rotation3D.RotationY = 270;
chart.Rotation3D.DepthPercents = 150;
// Take second chart series
IChartSeries series = chart.ChartData.Series[1];
// Now populating series data
series.DataPoints.AddDataPointForBarSeries(fact.GetCell(defaultWorksheetIndex, 1, 1, 20));
series.DataPoints.AddDataPointForBarSeries(fact.GetCell(defaultWorksheetIndex, 2, 1, 50));
series.DataPoints.AddDataPointForBarSeries(fact.GetCell(defaultWorksheetIndex, 3, 1, 30));
series.DataPoints.AddDataPointForBarSeries(fact.GetCell(defaultWorksheetIndex, 1, 2, 30));
series.DataPoints.AddDataPointForBarSeries(fact.GetCell(defaultWorksheetIndex, 2, 2, 10));
series.DataPoints.AddDataPointForBarSeries(fact.GetCell(defaultWorksheetIndex, 3, 2, 60));
// Set OverLap value
series.ParentSeriesGroup.Overlap = 100;
// Write presentation to disk
presentation.Save(dataDir + "Rotation3D_out.pptx", SaveFormat.Pptx);
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_Charts();
Presentation pres = new Presentation();
ISlide slide = pres.Slides[0];
IChart ch = pres.Slides[0].Shapes.AddChart(ChartType.ClusteredColumn, 100, 100, 600, 450);
ch.ChartData.Series.Clear();
ch.ChartData.Categories.Clear();
IChartDataWorkbook fact = ch.ChartData.ChartDataWorkbook;
fact.Clear(0);
int defaultWorksheetIndex = 0;
IChartCategory category = ch.ChartData.Categories.Add(fact.GetCell(0, "c2", "A"));
category.GroupingLevels.SetGroupingItem(1, "Group1");
category = ch.ChartData.Categories.Add(fact.GetCell(0, "c3", "B"));
category = ch.ChartData.Categories.Add(fact.GetCell(0, "c4", "C"));
category.GroupingLevels.SetGroupingItem(1, "Group2");
category = ch.ChartData.Categories.Add(fact.GetCell(0, "c5", "D"));
category = ch.ChartData.Categories.Add(fact.GetCell(0, "c6", "E"));
category.GroupingLevels.SetGroupingItem(1, "Group3");
category = ch.ChartData.Categories.Add(fact.GetCell(0, "c7", "F"));
category = ch.ChartData.Categories.Add(fact.GetCell(0, "c8", "G"));
category.GroupingLevels.SetGroupingItem(1, "Group4");
category = ch.ChartData.Categories.Add(fact.GetCell(0, "c9", "H"));
// Adding Series
IChartSeries series = ch.ChartData.Series.Add(fact.GetCell(0, "D1", "Series 1"),
ChartType.ClusteredColumn);
series.DataPoints.AddDataPointForBarSeries(fact.GetCell(defaultWorksheetIndex, "D2", 10));
series.DataPoints.AddDataPointForBarSeries(fact.GetCell(defaultWorksheetIndex, "D3", 20));
series.DataPoints.AddDataPointForBarSeries(fact.GetCell(defaultWorksheetIndex, "D4", 30));
series.DataPoints.AddDataPointForBarSeries(fact.GetCell(defaultWorksheetIndex, "D5", 40));
series.DataPoints.AddDataPointForBarSeries(fact.GetCell(defaultWorksheetIndex, "D6", 50));
series.DataPoints.AddDataPointForBarSeries(fact.GetCell(defaultWorksheetIndex, "D7", 60));
series.DataPoints.AddDataPointForBarSeries(fact.GetCell(defaultWorksheetIndex, "D8", 70));
series.DataPoints.AddDataPointForBarSeries(fact.GetCell(defaultWorksheetIndex, "D9", 80));
// Save presentation with chart
pres.Save(dataDir+"AsposeChart_out.pptx", Aspose.Slides.Export.SaveFormat.Pptx);
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_Charts();
// Create directory if it is not already present.
bool IsExists = System.IO.Directory.Exists(dataDir);
if (!IsExists)
System.IO.Directory.CreateDirectory(dataDir);
// Instantiate Presentation class that represents PPTX file
Presentation pres = new Presentation();
// Access first slide
ISlide sld = pres.Slides[0];
// Add chart with default data
IChart chart = sld.Shapes.AddChart(ChartType.ClusteredColumn, 0, 0, 500, 500);
// Setting chart Title
// Chart.ChartTitle.TextFrameForOverriding.Text = "Sample Title";
chart.ChartTitle.AddTextFrameForOverriding("Sample Title");
chart.ChartTitle.TextFrameForOverriding.TextFrameFormat.CenterText = NullableBool.True;
chart.ChartTitle.Height = 20;
chart.HasTitle = true;
// Set first series to Show Values
chart.ChartData.Series[0].Labels.DefaultDataLabelFormat.ShowValue = true;
// Setting the index of chart data sheet
int defaultWorksheetIndex = 0;
// Getting the chart data worksheet
IChartDataWorkbook fact = chart.ChartData.ChartDataWorkbook;
// Delete default generated series and categories
chart.ChartData.Series.Clear();
chart.ChartData.Categories.Clear();
int s = chart.ChartData.Series.Count;
s = chart.ChartData.Categories.Count;
// Adding new series
chart.ChartData.Series.Add(fact.GetCell(defaultWorksheetIndex, 0, 1, "Series 1"), chart.Type);
chart.ChartData.Series.Add(fact.GetCell(defaultWorksheetIndex, 0, 2, "Series 2"), chart.Type);
// Adding new categories
chart.ChartData.Categories.Add(fact.GetCell(defaultWorksheetIndex, 1, 0, "Caetegoty 1"));
chart.ChartData.Categories.Add(fact.GetCell(defaultWorksheetIndex, 2, 0, "Caetegoty 2"));
chart.ChartData.Categories.Add(fact.GetCell(defaultWorksheetIndex, 3, 0, "Caetegoty 3"));
// Take first chart series
IChartSeries series = chart.ChartData.Series[0];
// Now populating series data
series.DataPoints.AddDataPointForBarSeries(fact.GetCell(defaultWorksheetIndex, 1, 1, 20));
series.DataPoints.AddDataPointForBarSeries(fact.GetCell(defaultWorksheetIndex, 2, 1, 50));
series.DataPoints.AddDataPointForBarSeries(fact.GetCell(defaultWorksheetIndex, 3, 1, 30));
// Setting fill color for series
series.Format.Fill.FillType = FillType.Solid;
series.Format.Fill.SolidFillColor.Color = Color.Red;
// Take second chart series
series = chart.ChartData.Series[1];
// Now populating series data
series.DataPoints.AddDataPointForBarSeries(fact.GetCell(defaultWorksheetIndex, 1, 2, 30));
series.DataPoints.AddDataPointForBarSeries(fact.GetCell(defaultWorksheetIndex, 2, 2, 10));
series.DataPoints.AddDataPointForBarSeries(fact.GetCell(defaultWorksheetIndex, 3, 2, 60));
// Setting fill color for series
series.Format.Fill.FillType = FillType.Solid;
series.Format.Fill.SolidFillColor.Color = Color.Green;
// First label will be show Category name
IDataLabel lbl = series.DataPoints[0].Label;
lbl.DataLabelFormat.ShowCategoryName = true;
lbl = series.DataPoints[1].Label;
lbl.DataLabelFormat.ShowSeriesName = true;
// Show value for third label
lbl = series.DataPoints[2].Label;
lbl.DataLabelFormat.ShowValue = true;
lbl.DataLabelFormat.ShowSeriesName = true;
lbl.DataLabelFormat.Separator = "/";
// Save presentation with chart
pres.Save(dataDir + "AsposeChart_out.pptx", SaveFormat.Pptx);
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_Charts();
// Create directory if it is not already present.
bool IsExists = System.IO.Directory.Exists(dataDir);
if (!IsExists)
System.IO.Directory.CreateDirectory(dataDir);
// Instantiate the presentation// Instantiate the presentation
Presentation pres = new Presentation();