Exemple #1
0
        public static void Run()
        {
            //ExStart:PieChart
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_Charts();

            // Instantiate Presentation class that represents PPTX file
            Presentation presentation = new Presentation();

            // Access first slide
            ISlide slides = presentation.Slides[0];

            // Add chart with default data
            IChart chart = slides.Shapes.AddChart(ChartType.Pie, 100, 100, 400, 400);

            // Setting chart 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();

            // Adding new categories
            chart.ChartData.Categories.Add(fact.GetCell(0, 1, 0, "First Qtr"));
            chart.ChartData.Categories.Add(fact.GetCell(0, 2, 0, "2nd Qtr"));
            chart.ChartData.Categories.Add(fact.GetCell(0, 3, 0, "3rd Qtr"));

            // Adding new series
            IChartSeries series = chart.ChartData.Series.Add(fact.GetCell(0, 0, 1, "Series 1"), chart.Type);

            // Now populating series data
            series.DataPoints.AddDataPointForPieSeries(fact.GetCell(defaultWorksheetIndex, 1, 1, 20));
            series.DataPoints.AddDataPointForPieSeries(fact.GetCell(defaultWorksheetIndex, 2, 1, 50));
            series.DataPoints.AddDataPointForPieSeries(fact.GetCell(defaultWorksheetIndex, 3, 1, 30));

            // Not working in new version
            // Adding new points and setting sector color
            // series.IsColorVaried = true;
            chart.ChartData.SeriesGroups[0].IsColorVaried = true;

            IChartDataPoint point = series.DataPoints[0];

            point.Format.Fill.FillType             = FillType.Solid;
            point.Format.Fill.SolidFillColor.Color = Color.Cyan;
            // Setting Sector border
            point.Format.Line.FillFormat.FillType             = FillType.Solid;
            point.Format.Line.FillFormat.SolidFillColor.Color = Color.Gray;
            point.Format.Line.Width     = 3.0;
            point.Format.Line.Style     = LineStyle.ThinThick;
            point.Format.Line.DashStyle = LineDashStyle.DashDot;

            IChartDataPoint point1 = series.DataPoints[1];

            point1.Format.Fill.FillType             = FillType.Solid;
            point1.Format.Fill.SolidFillColor.Color = Color.Brown;

            // Setting Sector border
            point1.Format.Line.FillFormat.FillType             = FillType.Solid;
            point1.Format.Line.FillFormat.SolidFillColor.Color = Color.Blue;
            point1.Format.Line.Width     = 3.0;
            point1.Format.Line.Style     = LineStyle.Single;
            point1.Format.Line.DashStyle = LineDashStyle.LargeDashDot;

            IChartDataPoint point2 = series.DataPoints[2];

            point2.Format.Fill.FillType             = FillType.Solid;
            point2.Format.Fill.SolidFillColor.Color = Color.Coral;

            // Setting Sector border
            point2.Format.Line.FillFormat.FillType             = FillType.Solid;
            point2.Format.Line.FillFormat.SolidFillColor.Color = Color.Red;
            point2.Format.Line.Width     = 2.0;
            point2.Format.Line.Style     = LineStyle.ThinThin;
            point2.Format.Line.DashStyle = LineDashStyle.LargeDashDotDot;

            // Create custom labels for each of categories for new series
            IDataLabel lbl1 = series.DataPoints[0].Label;

            // lbl.ShowCategoryName = true;
            lbl1.DataLabelFormat.ShowValue = true;

            IDataLabel lbl2 = series.DataPoints[1].Label;

            lbl2.DataLabelFormat.ShowValue      = true;
            lbl2.DataLabelFormat.ShowLegendKey  = true;
            lbl2.DataLabelFormat.ShowPercentage = true;

            IDataLabel lbl3 = series.DataPoints[2].Label;

            lbl3.DataLabelFormat.ShowSeriesName = true;
            lbl3.DataLabelFormat.ShowPercentage = true;

            // Showing Leader Lines for Chart
            series.Labels.DefaultDataLabelFormat.ShowLeaderLines = true;

            // Setting Rotation Angle for Pie Chart Sectors
            chart.ChartData.SeriesGroups[0].FirstSliceAngle = 180;

            // Save presentation with chart
            presentation.Save(dataDir + "PieChart_out.pptx", SaveFormat.Pptx);
            //ExEnd:PieChart
        }
        public static void Run()
        {
            //ExStart:SettingCalloutForDataLabel
            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("chart.pptx", Aspose.Slides.Export.SaveFormat.Pptx);
        }
        public static void Run()
        {
            //ExStart:SetMarkerOptions
            // 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];

            // 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 image1 = (System.Drawing.Image) new Bitmap(dataDir + "aspose-logo.jpg");
            IPPImage             imgx1  = presentation.Images.AddImage(image1);

            // Set the picture
            System.Drawing.Image image2 = (System.Drawing.Image) new Bitmap(dataDir + "Tulips.jpg");
            IPPImage             imgx2  = presentation.Images.AddImage(image2);

            // 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;

            // Write presentation to disk
            presentation.Save(dataDir + "MarkOptions_out.pptx", SaveFormat.Pptx);
            //ExEnd:SetMarkerOptions
        }
        public static void Run()
        {
            //ExStart:ChartMarkerOptionsOnDataPoint
            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);

            String imagePath = @"C:\Users\Public\Pictures\Sample Pictures\";

            //Set the picture
            System.Drawing.Image img   = (System.Drawing.Image) new Bitmap(imagePath + "Desert.jpg");
            IPPImage             imgx1 = pres.Images.AddImage(img);

            //Set the picture
            System.Drawing.Image img2  = (System.Drawing.Image) new Bitmap(imagePath + "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);
        }