secondary xlvalue axis and title in Visual Basic 2010

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
Hell Exports,
I have below Visual Basic 2010 code to draw a chart using Excel then export to picture. I am not able to create the seondary value axis. i keep getting error "failed to call COM component". The problem is coming from the bolded section. However, why i remove
it the chart comes with secondary axis but problem i need to set an axis title which i am not able to do so. Can you please tell me what is the correct way to create a secondary axis and title in Excel.Interop?
Dim oExcel As Excel.Application<br/>
Dim oBook As Excel.Workbook<br/>
Dim ochart As Excel.Chart<br/>
Dim xlAxisX, xlAxisY1, xlAxisY2 As Excel.Axis<br/>
Dim OilSeries, LiqSeries, BSWSeries, WIRateSeries, ChokeSeries, GORSeries, TGLRSeries, LiftGasSeries, BHTSeries, BHPSeries, THPSeries As Excel.Series
<span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Verdana; color:#000000; font-size:x-small
Create an instance of Excel, and show it to the user.<br/>
oExcel = New Excel.Application()
Add a workbook.<br/>
oBook = oExcel.Workbooks.Add
Add a chart<br/>
ochart = oBook.Charts.Add
Set Properties of chart and axes<br/>
With ochart<br/>
.Name = "Well Test"<br/>
.ChartType = Excel.XlChartType.xlLineMarkers<br/>
.HasTitle = False<br/>
.AutoScaling = True<br/>
.HasAxis(Excel.XlAxisType.xlCategory, Excel.XlAxisGroup.xlPrimary) = True<br/>
.HasAxis(Excel.XlAxisType.xlCategory, Excel.XlAxisGroup.xlSecondary) = False<br/>
.HasAxis(Excel.XlAxisType.xlValue, Excel.XlAxisGroup.xlPrimary) = True<br/>
.HasAxis(Excel.XlAxisType.xlValue, Excel.XlAxisGroup.xlSecondary) = True<br/>
.Legend.Position = Excel.XlLegendPosition.xlLegendPositionBottom<br/>
End With
<br/>
Category X-Axis<br/>
xlAxisX = CType(ochart.Axes(Excel.XlAxisType.xlCategory, Excel.XlAxisGroup.xlPrimary), Excel.Axis)<br/>
xlAxisX.HasTitle = False<br/>
Primary Y-Axis<br/>
xlAxisY1 = CType(ochart.Axes(Excel.XlAxisType.xlValue, Excel.XlAxisGroup.xlPrimary), Excel.Axis)<br/>
xlAxisY1.HasTitle = True<br/>
xlAxisY1.AxisTitle.Text = "Oil Rate, Liquid Rate, BSW(%)*100"<br/>
Secondary Y-Axis <br/>
xlAxisY2 = CType(ochart.Axes(Excel.XlAxisType.xlValue, Excel.XlAxisGroup.xlSecondary), Excel.Axis) <br/>
xlAxisY2.HasTitle = True <br/>
xlAxisY2.AxisTitle.Text = "Choke, TGLR, GOR, BHP, THP, BHT, LiftGas Rate"


<br/>
<br/>

View the full article
 
Back
Top