Problem with Excel column chart

Hi. I am now trying to write a program that send a 2 row data in Excel and create Column Chart from the data cell.I already succeced to create Column Chart but I have some problem.Im using Visual Studio C#.NET.

1) labeling the Column chart.For Example if the chart data are from “B1"to"B5” the x (Axis) label should be "A1"to “A5”.

2) How to draw a line with a color on certain coodinate like x=50 in column chart?

below is the source that i wrote,im still new learner i hope you all can teach me.

Excel._Workbook book;
Excel._Worksheet sheet;
Excel._Chart c0;
Excel.Axis x,y;

sheet.get_Range(“K1”,“K8”).Select();
sheet.Name=“sheet1”;
book.Charts.Add(Missing.Value,Missing.Value,Missing.Value,Missing.Value);


c0=book.ActiveChart;
c0.ChartType= Excel.XlChartType.xlColumnClustered;
c0.HasTitle=true;
c0.ChartTitle.Text=“chart Title”;
x=(Excel.Axis)c0.Axes(Excel.XlAxisType.xlCategory,Excel.XlAxisGroup.xlPrimary);
x.HasTitle=true;
x.AxisTitle.Text=“Title-X”;
x.HasMajorGridlines=true;
x.HasMinorGridlines=false;
x.TickLabelSpacing=1;
x.TickMarkSpacing=1;

y=(Excel.Axis)c0.Axes(Excel.XlAxisType.xlValue,Excel.XlAxisGroup.xlPrimary);
y.HasTitle=true;
y.AxisTitle.Text=“title-Y”;
y.HasMajorGridlines=true;
y.HasMinorGridlines=false;

c0.SetSourceData(sheet.get_Range(“K1”,“K8”),Missing.Value);
c0.Location(Excel.XlChartLocation.xlLocationAsObject,sheet.Name);


the source only that data from sheet(“K1”,“K8”) so i want to make x-axis lable is start from “J1” to “J8”.and i also want to draw line for example straight line when x=50 in red color.
It seem to difficult to search the example and sample source for C#.NET.Most of them are in Basic.so I hope you all can help me.Thank you.

Hello,

A Quick question:

Are you using Microsoft Excel VBA, not Aspose.excel?

Thank you for reply.Actually I dont use Microsoft Excel VBA.I just start learning Visual Studio C#.NET. I just try learn using Excel Macro in the software that already can be used in Visual Studio C#.NET.So If you could teach and guild me using Aspose.excel. I really like learn and use it.Im still new and i dont know which is the best and simple.

Hi, thanks for your consideration.

In Aspose.Excel, you can have an easy way to set a chart. For example, if you want to create a column chart with the source data on B1 to B3, you can create a designer file and create the chart as you need. Then you can use Aspose.Excel fill the data to cell B1 to B5.

Sample:

Excel excel = new Excel();

//Open the designer file you created
excel.Open(“c:\mychart.xls”);

//Put data
Cells cells = excel.Worksheets[0].Cells;
cells[“B1”].PutValue(1);
cells[“B2”].PutValue(2);
cells[“B3”].PutValue(3);

//Save result file to disk
excel.Save(“c:\resultchart.xls”, FileFormatType.Default);


Hello,

Why not Excel macro? Why Aspose.excel?

Please check Why Not Automation.