hi - as you can see on the graph, the leading line for the slice “cash” is such that the label is touching the pie chart. Could you please fix this? Thank you
Hi Philip,
public System.Drawing.Bitmap CreatePieChart(System.Data.DataTable sourceTable, int sizeX, int sizeY)
{
if (sourceTable == null || sourceTable.Rows.Count == 0) throw new Exception(“No table to create pie chart”);
if (sourceTable.Columns.Count != 2) throw new Exception(“pie chart needs two columns of type (string,double)”);
System.Data.DataTable table = CommonClasses.DataTableUtility.SortMaxMin(sourceTable, “value”);
Aspose.Cells.Workbook workbook = new Aspose.Cells.Workbook();
Aspose.Cells.Worksheet sheet = workbook.Worksheets[0];
for (int r = 0; r < table.Rows.Count; r++)
{
string aCell = “A” + (r + 1);
string bCell = “B” + (r+ 1);
double value = double.Parse(table.Rows[r][“value”].ToString());
sheet.Cells[aCell].PutValue(table.Rows[r][“label”].ToString());
sheet.Cells[bCell].PutValue(value);
}
Aspose.Cells.Charts.Chart productsChart;
int chartIdx = sheet.Charts.Add(Aspose.Cells.Charts.ChartType.Pie, 0, 0, sizeX, sizeY);
productsChart = sheet.Charts[chartIdx];
//Gets the cells that define the data to be charted
int seriesIdx = productsChart.NSeries.Add("=Sheet1!$B$1:$B$" + table.Rows.Count, true);
Aspose.Cells.Charts.DataLabels dataLabels = productsChart.NSeries[0].DataLabels;
dataLabels.ShowCategoryName = true;
dataLabels.ShowPercentage = true;
dataLabels.ShowValue = false;
dataLabels.ShowLegendKey = false;
dataLabels.Font.Name = “Arial”;
dataLabels.Font.Size = 7;
dataLabels.NumberFormat = “0.0%”;
dataLabels.Separator = Aspose.Cells.Charts.DataLablesSeparatorType.NewLine;
productsChart.ShowLegend = false;
productsChart.PlotArea.Height = 2800;
productsChart.PlotArea.Width = 2800;
productsChart.PlotArea.X = 500;
productsChart.PlotArea.Y = 500;
productsChart.NSeries[seriesIdx].HasLeaderLines = true;
productsChart.ChartArea.Border.FormattingType = Aspose.Cells.Charts.ChartLineFormattingType.None;
Aspose.Cells.Charts.Series nSeries = productsChart.NSeries[seriesIdx];
nSeries.XValues = "=Sheet1!$A$1:$A$" + table.Rows.Count;
return (productsChart.ToImage());
}
Hi Philip,
Hi,
I can’t. How can I make the pie chart smaller but keep the overall plotarea the same?
Hi,
Remarks
The plot-area bounding box includes the plot area, tick marks(tick labels), and a small border around the tick marks. If the value is not created by MS Excel, please call Chart.Calculate() method before calling this method.
The X, Y, Width and Height of PlotArea represents the plot-area bounding box that includes the plot area, tick marks(tick labels), and a small border around the tick marks. If you want to get actual size of plot area, you should call InnerX, InnerY, InnerWidth and InnerHeight properties.
For excel 2007 or latter, the default value is zero. you should call get the value after calling Chart.Calculate().
hi - doesn’t the innerX etc suppose to be the size of the pie without the tick marks?
Hi,
InnerY, InnerWidth and InnerHeight properties to get the actual size and position without marks.