Chart Properties


Hello

I have Attched a Excel fil in which 1st sheet (Readmission Graph) which is generating one graph.

1. I want to know how to give space between each Pyramids ?

2. In sheet 2 i have added one more picture for the same chart (Manually i changed the style), can we get the same design at code level. or is there any property which will tell me the default styles present for the chart ?

Please help me out to give some attractive styles for the chart.

Reagrds
Mohammed Irfan

Hi Irfan,

Thanks for providing us the template file.

1). Could you give us details, how could you do this in MS Excel to allot spaces for Pyramid chart, we will check it soon. I tried in MS Excel but in vain.

2). I have created the code segment using your template file to obtain chart's source data in the first sheet for your requirement so you may refer to it. The code may not create 100% identical your desired chart as there might be some minor differences regarding chart's formatting or other attributes but it will give you insight about the usage of different APIs involved and you may change / modify the codes for your need.

Sample code:

Workbook workbook = new Workbook();
workbook.Open("f:\\test\\ReAdmissionReport_200906041040+.xls");
//RGB Values for your desired chart's series gradient colors
//Draw custom colors.
Color color1, color2, color3, color4, color5, color6, color7;
color1 = Color.FromArgb(59, 114, 167);
color2 = Color.FromArgb(170, 70, 67);
color3 = Color.FromArgb(137, 165, 78);
color4 = Color.FromArgb(113, 88, 143);
color5 = Color.FromArgb(65, 152, 175);
color6 = Color.FromArgb(219, 132, 61);
color7 = Color.FromArgb(147, 169, 207);
//Add to excel color palette.
workbook.ChangePalette(color1, 55);
workbook.ChangePalette(color2, 54);
workbook.ChangePalette(color3, 53);
workbook.ChangePalette(color4, 52);
workbook.ChangePalette(color5, 51);
workbook.ChangePalette(color6, 50);
workbook.ChangePalette(color7, 49);

Worksheet sheet = workbook.Worksheets[workbook.Worksheets.Add()];
//Create chart
int chartIndex = sheet.Charts.Add(ChartType.Pyramid, 1, 3, 31, 11);
Chart chart = sheet.Charts[chartIndex];
//Set properties of chart
chart.Walls.ForegroundColor = Color.Transparent;
chart.Walls.Border.IsVisible = false;
chart.Floor.Border.Style = LineType.Solid;
chart.Floor.Border.Weight = WeightType.HairLine;
chart.Floor.ForegroundColor = Color.Transparent;
chart.Floor.Border.Color = Color.Gray;

chart.Elevation = 15;
chart.Rotation = 20;
chart.PlotArea.Border.IsVisible = false;
chart.PlotArea.Area.ForegroundColor = Color.Transparent;
chart.PlotArea.Border.IsVisible = false;
chart.IsLegendShown = true;
chart.Legend.AutoScaleFont = false;
chart.Legend.TextFont.Name = "Calibri";
chart.Legend.TextFont.Size = 10;
//chart.ChartObject.Height = 900;
//chart.ChartObject.Width = 450;
chart.Legend.Border.IsVisible = false;

chart.GapWidth = 150;
chart.GapDepth = 150;
chart.DepthPercent = 100;

//Set properties of nseries
chart.NSeries.Add("=Re-Admission Graph!B1:B7", false);
//chart.NSeries.CategoryData = "A1:A7";

//chart.NSeries[0].XValues = "Sheet1!A2:A10";
NSeries nseries = chart.NSeries;
for (int i = 0; i < nseries.Count; i++)
{
nseries[i].Name = workbook.Worksheets[0].Cells[i, 0].Value.ToString();

}

nseries[0].Area.FillFormat.SetOneColorGradient(color1, 0, GradientStyleType.Horizontal, 2);
nseries[1].Area.FillFormat.SetOneColorGradient(color2, 0, GradientStyleType.Horizontal, 2);
nseries[2].Area.FillFormat.SetOneColorGradient(color3, 0, GradientStyleType.Horizontal, 2);
nseries[3].Area.FillFormat.SetOneColorGradient(color4, 0, GradientStyleType.Horizontal, 2);
nseries[4].Area.FillFormat.SetOneColorGradient(color5, 0, GradientStyleType.Horizontal, 2);
nseries[5].Area.FillFormat.SetOneColorGradient(color6, 0, GradientStyleType.Horizontal, 2);
nseries[6].Area.FillFormat.SetOneColorGradient(color7, 0, GradientStyleType.Horizontal, 2);


//Set properties of chart title
chart.Title.Text = "Re Admission Count As of 6/4/2009\n 10:40:38 AM";
chart.Title.TextFont.Color = Color.Black;
chart.Title.TextFont.IsBold = true;
chart.Title.TextFont.Size = 18;
chart.Title.TextFont.Name = "Calibri";

//Set properties of Axis(categoryaxis) title
Axis categoryAxis = chart.CategoryAxis;
categoryAxis.Title.TextFont.Color = Color.Black;
categoryAxis.Title.TextFont.Size = 10;
categoryAxis.Title.TextFont.Name = "Calibri";
//categoryAxis.MajorTickMark = TickMarkType.l
categoryAxis.MinorTickMark = TickMarkType.None;
categoryAxis.TickLabelPosition = TickLabelPositionType.NextToAxis;
categoryAxis.TickLabelSpacing = 1;
categoryAxis.TickMarkSpacing = 1;

//Set properties of valueaxis
chart.ValueAxis.Title.TextFont.Color = Color.Black;
chart.ValueAxis.Title.TextFont.Size = 10;
chart.ValueAxis.Title.TextFont.Name = "Arial";
chart.ValueAxis.MaxValue = 14;
chart.ValueAxis.MinValue = 0;
chart.ValueAxis.MajorTickMark = TickMarkType.Cross;
chart.ValueAxis.MinorTickMark = TickMarkType.None;
chart.ValueAxis.TickLabelPosition = TickLabelPositionType.NextToAxis;


workbook.Save("f:\\test\\output_pyramidchart.xls");

Also, the output file is attached for your reference.

Thank you.


Hi Amjad

Thanks for your help…

It Worked n i got almost similer output.

Could you please let me know is there any default Types for Charts ?

any class is there in Aspose.Cell Dll ??

Regards
Mohammed Irfan

Hi Irfan,

irfansa:


Could you please let me know is there any default Types for Charts ?

any class is there in Aspose.Cell Dll ??

What do you mean by default types of charts, well, Aspose.Cells does support all the standard and advanced chart types (2D and 3D oriented) that MS Excel support with all types of formattings, check the Aspose.Cells.ChartType API (enumeration) for reference: ChartType Enumeration

Thank you.