ShapeCollection.AddShapeInChartByScale

AddShapeInChartByScale(MsoDrawingType, PlacementType, double, double, double, double)

Add a shape to chart. All unit is percent scale of chart area.

public Shape AddShapeInChartByScale(MsoDrawingType type, PlacementType placement, double left, 
    double top, double right, double bottom)
ParameterTypeDescription
typeMsoDrawingTypeThe drawing type.
placementPlacementTypethe placement type.
leftDoubleUnit is percent scale of chart area width.
topDoubleUnit is percent scale of chart area height.
rightDoubleUnit is percent scale of chart area width.
bottomDoubleUnit is percent scale of chart area height.

Examples

using System;
using Aspose.Cells;
using Aspose.Cells.Drawing;
using System.Drawing;

namespace AsposeCellsExamples
{
    public class ShapeCollectionMethodAddShapeInChartByScaleWithMsoDrawingTypePlacementTypeDouDemo
    {
        public static void Run()
        {
            // Create a new workbook
            Workbook workbook = new Workbook();
            Worksheet worksheet = workbook.Worksheets[0];

            // Add sample data for the chart
            worksheet.Cells["A1"].PutValue("Category");
            worksheet.Cells["A2"].PutValue("A");
            worksheet.Cells["A3"].PutValue("B");
            worksheet.Cells["A4"].PutValue("C");
            worksheet.Cells["B1"].PutValue("Value");
            worksheet.Cells["B2"].PutValue(10);
            worksheet.Cells["B3"].PutValue(20);
            worksheet.Cells["B4"].PutValue(30);

            // Add a chart
            int chartIndex = worksheet.Charts.Add(Aspose.Cells.Charts.ChartType.Column, 5, 1, 20, 10);
            Aspose.Cells.Charts.Chart chart = worksheet.Charts[chartIndex];
            chart.SetChartDataRange("A1:B4", true);

            // Calculate chart
            chart.Calculate();

            // Add a rectangle shape to the chart using scale coordinates
            Shape rectangle = chart.Shapes.AddShapeInChartByScale(
                MsoDrawingType.Rectangle, 
                PlacementType.Move,
                0.2,  // x1 (20% from left)
                0.2,  // y1 (20% from top)
                0.4,  // x2 (40% from left)
                0.4); // y2 (40% from top)
            rectangle.Fill.SolidFill.Color = Color.Blue;
            rectangle.Line.SolidFill.Color = Color.Black;

            // Add an oval shape to the chart using scale coordinates
            Shape oval = chart.Shapes.AddShapeInChartByScale(
                MsoDrawingType.Oval,
                PlacementType.Move,
                0.6,  // x1 (60% from left)
                0.6,  // y1 (60% from top)
                0.8,  // x2 (80% from left)
                0.8); // y2 (80% from top)
            oval.Fill.SolidFill.Color = Color.Red;
            oval.Line.SolidFill.Color = Color.Black;

            // Save the workbook
            workbook.Save("AddShapeInChartByScaleWithMsoDrawingType.xlsx");
        }
    }
}

See Also


AddShapeInChartByScale(MsoDrawingType, PlacementType, double, double, double, double, byte[])

Add a shape to chart .All unit is 1/4000 of chart area.

public Shape AddShapeInChartByScale(MsoDrawingType type, PlacementType placement, double left, 
    double top, double right, double bottom, byte[] imageData)
ParameterTypeDescription
typeMsoDrawingTypeThe drawing type.
placementPlacementTypethe placement type.
leftDoubleUnit is percent scale of chart area width.
topDoubleUnit is percent scale of chart area height.
rightDoubleUnit is percent scale of chart area width.
bottomDoubleUnit is percent scale of chart area height.
imageDataByte[]If the shape is not a picture or ole object,imageData should be null.

See Also