How to remove border around image in Aspose


#1

I have a chart and i am converting it to image.When I convert it to image there is a border around the image.How can i remove this?

Workbook workbook1 = new Workbook();
Worksheet worksheet1 = workbook1.Worksheets[0];

worksheet1.Cells[0, 0].PutValue("Apple");
worksheet1.Cells[0, 1].PutValue(324234234239);
worksheet1.Cells[0, 2].PutValue(3209496298.35049);

worksheet1.Cells[1, 0].PutValue("Orange");
worksheet1.Cells[1, 1].PutValue(12123123);
worksheet1.Cells[1, 2].PutValue(202342342);

worksheet1.Cells[2, 0].PutValue("Mango");
worksheet1.Cells[2, 1].PutValue(12123123);
worksheet1.Cells[2, 2].PutValue(202342342);
int chartIndex1 = worksheet1.Charts.Add(ChartType.Column3DClustered, 5, 0, 15, 5);

Chart chart1 = worksheet1.Charts[chartIndex1];

chart1.Title.Text = "Quantity for period 6 / 2016";
chart1.Title.Font.Size = 6;

chart1.NSeries.CategoryData = "A1:A3";
chart1.CategoryAxis.TickLabels.Font.Size = 6;

chart1.ChartArea.BackgroundMode = BackgroundMode.Transparent;
chart1.NSeries.Add("B1: B3", true);
chart1.NSeries.Add("C1: C3", true);
chart1.NSeries[0].XValues = "A1: A3";
chart1.NSeries[1].XValues = "A1: A3";
chart1.NSeries[0].Name = "Quantity Balance";
chart1.NSeries[1].Name = "Net Available";
chart1.NSeries[0].DataLabels.ShowValue = true;
chart1.NSeries[0].DataLabels.Font.Size = 6;
chart1.NSeries[0].Area.ForegroundColor = Color.Red;
chart1.NSeries[1].DataLabels.ShowValue = true;
chart1.NSeries[1].DataLabels.Font.Size = 6;
chart1.NSeries[1].Area.ForegroundColor = Color.Green;
chart1.Legend.Position = LegendPositionType.Bottom;
chart1.Legend.Font.Size = 6;
chart1.PlotArea.Area.Formatting = FormattingType.None;
chart1.PlotArea.Border.FormattingType = ChartLineFormattingType.None;
ImageOrPrintOptions options1 = new ImageOrPrintOptions()
{
	VerticalResolution = 173,
	HorizontalResolution = 200,
	SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality
};
Image chartImage1 = chart1.ToImage(options1);
byte[] newImage1 = ConvertImageToByte(chartImage1);
string image1 = Convert.ToBase64String(newImage1);

#2

@anishsm,

Thanks for sample code and details.

Please add the following lines (in bold) to your code segment, it will work for your needs:
e.g
Sample code:


chart1.NSeries.CategoryData = “A1:A3”;
chart1.CategoryAxis.TickLabels.Font.Size = 6;

chart1.ChartArea.BackgroundMode = BackgroundMode.Transparent;
chart1.NSeries.Add(“B1: B3”, true);
chart1.NSeries.Add(“C1: C3”, true);
chart1.NSeries[0].XValues = “A1: A3”;
chart1.NSeries[1].XValues = “A1: A3”;
chart1.NSeries[0].Name = “Quantity Balance”;
chart1.NSeries[1].Name = “Net Available”;
chart1.NSeries[0].DataLabels.ShowValue = true;
chart1.NSeries[0].DataLabels.Font.Size = 6;
chart1.NSeries[0].Area.ForegroundColor = Color.Red;
chart1.NSeries[1].DataLabels.ShowValue = true;
chart1.NSeries[1].DataLabels.Font.Size = 6;
chart1.NSeries[1].Area.ForegroundColor = Color.Green;
chart1.Legend.Position = LegendPositionType.Bottom;
chart1.Legend.Font.Size = 6;
chart1.PlotArea.Area.Formatting = FormattingType.None;
chart1.PlotArea.Border.FormattingType = ChartLineFormattingType.None;

chart1.ChartArea.Area.Formatting = FormattingType.None;
chart1.ChartArea.Border.FormattingType = ChartLineFormattingType.None;

ImageOrPrintOptions options1 = new ImageOrPrintOptions()
{
VerticalResolution = 173,
HorizontalResolution = 200,
SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality
};

Hope this helps a bit.


#3

Thank you so much ! worked fine. I have one more doubt.How can we remove the unwanted white space on the sides of chart image ?


#4

@anishsm,

Well, the white space on the sides of the chart is a part of chart area, so you cannot remove it. You may set/minimize the width/height of the chart and its objects though.