Turn your Mobile Apps into m-commerce apps – Learn More!

You're Browsing As A Guest! Register Now...
Become a VB.NET Expert!

Join 414,938 VB.NET Programmers for FREE! Get instant access to thousands of VB.NET experts, tutorials, code snippets, and more! There are 2,680 people online right now.Registration is fast and FREE... Join Now!



Page 1 of 1
  • You cannot start a new topic
  • Reply Reply

adding second y-axis into the chart.HOW? Rate Topic: -----

#1 bellaelysium  Icon User is offline

  • New D.I.C Head
  • Pip

Reputation: 2
  • View blog
  • Posts: 32
  • Joined: 08-June 08


Dream Kudos: 0

Share |

adding second y-axis into the chart.HOW?

Posted 16 June 2008 - 12:45 AM

Is it possible to convert VBA to VB 2005 code?

I actually record the excel marco as I insert the chart and format it. Then taking the VBA code from there.

Now I need to create a chart in excel using VB 2005 so I was wondering if anyone could guide me on converting the code?


here's the VBA code:

Charts.Add
	ActiveChart.ChartType = xlLine
	ActiveChart.SetSourceData Source:=Sheets("Copy of 

trial").Range("A1:H23"), _
		PlotBy:=xlColumns
	ActiveChart.Location Where:=xlLocationAsNewSheet
	With ActiveChart
		.HasTitle = True
		.ChartTitle.Characters.Text = "Animal Rack Monitor"
		.Axes(xlCategory, xlPrimary).HasTitle = True
		.Axes(xlCategory, xlPrimary).AxisTitle.Characters.Text = 

"Time/Date"
		.Axes(xlValue, xlPrimary).HasTitle = True
		.Axes(xlValue, xlPrimary).AxisTitle.Characters.Text = 

"Measurements"
	End With
	With ActiveChart.Axes(xlCategory)
		.HasMajorGridlines = True
		.HasMinorGridlines = True
	End With
	With ActiveChart.Axes(xlValue)
		.HasMajorGridlines = True
		.HasMinorGridlines = True
	End With
	ActiveChart.HasLegend = True
	ActiveChart.Legend.Select
	Selection.Position = xlRight
	ActiveChart.SeriesCollection(1).Select
	With Selection.Border
		.ColorIndex = 57
		.Weight = xlMedium
		.LineStyle = xlContinuous
	End With
	With Selection
		.MarkerBackgroundColorIndex = xlNone
		.MarkerForegroundColorIndex = xlNone
		.MarkerStyle = xlNone
		.Smooth = False
		.MarkerSize = 3
		.Shadow = False
	End With
	ActiveChart.SeriesCollection(1).AxisGroup = 2
	ActiveChart.SeriesCollection(4).Select
	With Selection.Border
		.ColorIndex = 57
		.Weight = xlMedium
		.LineStyle = xlContinuous
	End With
	End Sub




So far I have already done the opening of excel file and putting in Excel namespace:

		
		Dim objExcelC As Excel.Chart


		WExcel.Charts.Add()
		objExcelC = WBook.ActiveChart
		objExcelC.Activate()

		objExcelC.ChartType = Excel.XlChartType.xlLineMarkers
		objExcelC.SetSourceData(Source:=range)

		objExcelC.Name = "ARM Chart"
		objExcelC.HasTitle = True
		objExcelC.ChartTitle.Text = "Animal Rack Monitor"



	End Sub
End Class





When I tried running, the axis in opposite to what I want.
I tried ways to correct it and inserting more code (refering to VBA code) but errors occurs, like xlLines , xlColumns are not declared...etc.


I dunno how to proceed on.

HELP..guidance??!!

This post has been edited by bellaelysium: 16 June 2008 - 10:05 PM

Was This Post Helpful? 0
  • +
  • -


#2 bellaelysium  Icon User is offline

  • New D.I.C Head
  • Pip

Reputation: 2
  • View blog
  • Posts: 32
  • Joined: 08-June 08


Dream Kudos: 0

Re: adding second y-axis into the chart.HOW?

Posted 16 June 2008 - 10:02 PM

So far, I wrote this code:

WExcel.Charts.Add()
		objExcelC = WBook.ActiveChart
		objExcelC.Activate()
		objExcelC.ChartType = Excel.XlChartType.xlLine
		objExcelC.SetSourceData(Source:=range, PlotBy:=_
Excel.XlRowCol.xlColumns)
		objExcelC.Name = "ARM Chart"
		objExcelC.HasTitle = True
		objExcelC.ChartTitle.Text = "Animal Rack Monitor"

		With objExcelC
			xlsAxisCategory = .Axes(, Excel.XlAxisGroup.xlPrimary)
			xlsAxisCategory.Item(Excel.XlAxisType.xlCategory)._
HasTitle = True
			xlsAxisCategory.Item(Excel.XlAxisType.xlCategory)._
AxisTitle.Characters.Text = "Time/Date"
			xlsAxisCategory.Item(Excel.XlAxisType.xlCategory)._
HasMajorGridlines = True
			xlsAxisCategory.Item(Excel.XlAxisType.xlCategory)._
HasMinorGridlines = True

			xlsAxisValue = .Axes(, Excel.XlAxisGroup.xlPrimary)
			xlsAxisValue.Item(Excel.XlAxisType.xlValue)._
HasTitle = True
			xlsAxisValue.Item(Excel.XlAxisType.xlValue)._
AxisTitle.Characters.Text = "Measurements"
			xlsAxisValue.Item(Excel.XlAxisType.xlValue)._
HasMajorGridlines = True
			xlsAxisValue.Item(Excel.XlAxisType.xlValue)._
HasMinorGridlines = True


		End With



I need some guidance in adding second y-axis into the chart.


here's the VBA code where I select one data to display as second y-axis ( I recorded the Excel Macro):

ActiveChart.SeriesCollection(1).Select
	ActiveChart.SeriesCollection(1).AxisGroup = 2 



The graph and all run to what I want.

But now, I want only one series of data to be plot themselves in second y-axis instead of me selecting it.
the ideal graph I manually plot in in the attachment.


Any guidance? Thanks!

Attached File(s)


Was This Post Helpful? 0
  • +
  • -

#3 bellaelysium  Icon User is offline

  • New D.I.C Head
  • Pip

Reputation: 2
  • View blog
  • Posts: 32
  • Joined: 08-June 08


Dream Kudos: 0

Re: adding second y-axis into the chart.HOW?

Posted 17 June 2008 - 06:56 PM

Matter resolved.

Was able to add in after figuring out. :)

This post has been edited by bellaelysium: 17 June 2008 - 06:57 PM

Was This Post Helpful? 0
  • +
  • -

#4 Jayman  Icon User is offline

  • Student of Life
  • Icon

Reputation: 380
  • View blog
  • Posts: 9,352
  • Joined: 26-December 05


Dream Kudos: 500

Expert In: Everything

Re: adding second y-axis into the chart.HOW?

Posted 17 June 2008 - 08:49 PM

Good job at arriving at a solution for your problem. :)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1
  • You cannot start a new topic
  • Reply Reply


Fast Reply

  

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users