Not able to plot chart in the chartspace inside userform in excel VB

sharathdude
05-13-2010, 10:58 PM
Hello people,

I have started using excel VB editor from past 1week so my knowledge in VB is very minimal, please excuse me if the clarification sought by me seem stupid to some of you.

I have created a userform in excel VB editor in which i want to create a live XYscattersmoothline chart in a chartspace. The values for the chart should be read from the excel sheet. I have written the following code:

Dim Spreadsheet1 As OWC10.Spreadsheet
' Add a chart.
ChartSpace1.Clear
ChartSpace1.Refresh
ChartSpace1.Charts.Add

' Set the data source of the chart to the Spreadsheet control.
Set Spreadsheet1 = CreateObject("OWC10.Spreadsheet")
Spreadsheet1.Range("A1", "Z1000") = Sheet2.Range("A1", "Z1000").Value

Set c = ChartSpace1.Constants
Set ChartSpace1.DataSource = Spreadsheet1

' Create a Xy scatter chart chart.
ChartSpace1.Charts(0).Type = chChartTypeScatterSmoothLine

'Set the maximum and minimum axis values
ChartSpace1.Charts(0).Scalings(chDimXValues).Maximum = 1200
ChartSpace1.Charts(0).Scalings(chDimXValues).Minimum = -9000
ChartSpace1.Charts(0).Axes(chAxisPositionLeft).MajorUnit = 2500
ChartSpace1.Charts(0).Axes(chAxisPositionLeft).MinorUnit = 500
ChartSpace1.Charts(0).Axes(1).CrossesAtValue = 0
ChartSpace1.Charts(0).Scalings(chDimYValues).Maximum = 5500
ChartSpace1.Charts(0).Scalings(chDimYValues).Minimum = -4500
ChartSpace1.Charts(0).Axes(chAxisPositionBottom).MajorUnit = 2000
ChartSpace1.Charts(0).Axes(chAxisPositionBottom).MinorUnit = 400
ChartSpace1.Charts(0).Axes(xlAxisCrossesCustom).CrossesAtValue = 0
' Add two data series to the chart.
'ChartSpace1.Charts(0).SeriesCollection.Add
'ChartSpace1.Charts(0).SeriesCollection.Add

' Set the properties of the first data series.
'ChartSpace1.Charts(0).SeriesCollection(0).SetData chDimSeriesNames, 0, "a"
ChartSpace1.Charts(0).SetData chDimYValues, 0, "M6:M17"
ChartSpace1.Charts(0).SetData chDimXValues, 0, "N6:N17"


' Set the properties of the second data series.
'ChartSpace1.Charts(0).SeriesCollection(1).SetData chDimSeriesNames, 0, "c"
'ChartSpace1.Charts(0).SeriesCollection(1).SetData chDimValues, 0, "j21:j22"


' Display the legend.
ChartSpace1.Charts(0).HasLegend = True

I want to create chart with

XAxis crossingcrossing at value = 0
Range of X axis:
Maximum = 1200
Minimum = -9000
Major unit = 2500
Minor unit = 500
Major gridlines displayed
specify yellow color for major grid lines

Similarly for YAxis crossingcrossing at value = 0
Range of Y axis:
Maximum = 4500
Minimum = -5500
Major unit = 2000
Minor unit = 400
Major gridlines displayed
specify yellow color for major grid lines

I also want to change the background color for the chart

I want to specify data range and create dataseries to plot lines on the XYscattersmoothline graph. In the code above I am not able to read the data from the cell range from the spread sheet specified.

I am also attaching the image file of the graph I am trying to create and also the excel file which contains the VB code.

Kindly help

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum