We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Want to generate chart

Hi,

Here I am attaching excel file in which one bar chart is generated but data are coming from database(using datatable).Now I want to generate same bar using Aspose.cell .Kindly give me some code which will generate sample bar.There will be three column in datatable using which we have to generate bar graph.Important thing is ,I have to do these all things in existing opened Ms-excel sheet only.Plz tell me the way how we can do this ASAP.

Thanks in advance
Rajesh Kumar,
India

Hi Rajesh,

Thanks for providing us the template file containing your desired chart.

May the following sample code help you to create your desired chart, kindly consult it. I have used your template file as a data source for the column chart and created the chart using the Aspose.Cells for .NET APIs. The output file is also attached for your reference. You can change the code to implement your further attributes and settings for the chart.

Sample code:

[C#]

Workbook workbook = new Workbook();
workbook.Open("f:\\test\\ChartTest.xls");
Worksheet worksheet = workbook.Worksheets[0];
Cells cells = worksheet.Cells;

int ChartIndex = workbook.Worksheets[0].Charts.Add(ChartType.Column,9, 0, 38, 10);
Chart Ch = workbook.Worksheets[0].Charts[ChartIndex];

Ch.NSeries.Add("Concentration!D10:E29", true);
Ch.NSeries.CategoryData = "Concentration!C10:C29";

ASeries S;
S = Ch.NSeries[0];
S.Name = "Current";
S.Area.FillFormat.SetOneColorGradient(Color.Yellow, 0, GradientStyleType.Horizontal,2);

S = Ch.NSeries[1];
S.Name = "MMM-YY";
S.Area.FillFormat.SetOneColorGradient(Color.Green, 0, GradientStyleType.Vertical, 2);

Title vtitle = Ch.ValueAxis.Title;
vtitle.Text = "% Total Shares Outstanding";
vtitle.TextFont.IsBold = true;
vtitle.TextFont.Size = 11;
vtitle.TextFont.Name = "Book Antiqua";

Ch.PlotArea.Area.ForegroundColor = Color.White;
Ch.ChartArea.Border.IsVisible = false;

Ch.CategoryAxis.MajorGridLines.IsVisible = false;



Ch.IsLegendShown = true;
Ch.PlotArea.Border.IsVisible = false;

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


[VB]

Dim workbook As New Workbook()
workbook.Open("f:\test\ChartTest.xls")
Dim worksheet As Worksheet = workbook.Worksheets(0)
Dim cells As Cells = worksheet.Cells

Dim ChartIndex As Integer = workbook.Worksheets(0).Charts.Add(ChartType.Column,9, 0, 38, 10)
Dim Ch As Chart = workbook.Worksheets(0).Charts(ChartIndex)

Ch.NSeries.Add("Concentration!D10:E29", True)
Ch.NSeries.CategoryData = "Concentration!C10:C29"

Dim S As ASeries
S = Ch.NSeries(0)
S.Name = "Current"
S.Area.FillFormat.SetOneColorGradient(Color.Yellow, 0, GradientStyleType.Horizontal,2)

S = Ch.NSeries(1)
S.Name = "MMM-YY"
S.Area.FillFormat.SetOneColorGradient(Color.Green, 0, GradientStyleType.Vertical, 2)

Dim vtitle As Title = Ch.ValueAxis.Title
vtitle.Text = "% Total Shares Outstanding"
vtitle.TextFont.IsBold = True
vtitle.TextFont.Size = 11
vtitle.TextFont.Name = "Book Antiqua"

Ch.PlotArea.Area.ForegroundColor = Color.White
Ch.ChartArea.Border.IsVisible = False

Ch.CategoryAxis.MajorGridLines.IsVisible = False

Ch.IsLegendShown = True
Ch.PlotArea.Border.IsVisible = False

workbook.Save("f:\test\Output_Chart1.xls")

Hopefully, it will help you understanding and implementing the apis to create your desired chart.

Thank you.