Bug with pie chart

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,


Thanks for your inquiry. Was this document (newsletter_DODDGLOB_20140831.doc) generated by using Aspose.Words? If yes, what code did you use to generate it on your end and could you please attach your input document you used to generate this document here for testing? We will investigate the issue on our end and provide you more information.

Also, please try the latest version of Aspose.Words 14.9.0 and see how it goes?
http://www.aspose.com/community/files/51/.net-components/aspose.words-for-.net/default.aspx

Best regards,

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,


Thanks for your inquiry. Your query seems to be more related to Aspose.Cells API. I am moving your thread in Aspose.Cells forum where you’ll be guided appropriately.

Best regards,

Hi,


Well, it looks like you are creating chart and then rendering image of the chart using Aspose.Cells APIs. Do you find issue “the slice “cash” is such that the label is touching the pie chart” regarding rendered image or in the original chart in MS Excel file format? I think you may try to extend the chart area/plot area a bit (set/ extend its width and height a bit), so the leader line for the slice cash do not touch it, see the sample lines of code:
e.g
Sample code:

productsChart.ChartObject.Height = 400;
productsChart.ChartObject.Width = 500;

For your information, if the slice is small or chart’s plot area’s width/height is minimal, you may see labels overwriting each other or leader lines touching the slices or labels etc., so you may try to extend the chart’s area/ plot area’s width/ height a bit accordingly.

Thank you.

I can’t. How can I make the pie chart smaller but keep the overall plotarea the same?

Hi,


Well, I am afraid, there is no better way to cope with it as you have to extend the width/ height of the chart object. Anyways, you may try to use PlotArea.Width and PlotArea.Height attributes accordingly:
e.g
Sample code:

chart.PlotArea.Width = 4000;
chart.PlotArea.Height = 3500;

I will paste the remarks for these properties for your reference:

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().


Hope, it helps a bit.

Thank you.

hi - doesn’t the innerX etc suppose to be the size of the pie without the tick marks?

Hi,


Yes, you may use InnerX,
InnerY, InnerWidth and InnerHeight properties to get the actual size and position without marks.

Thank you.