Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to change chart Y value on the web by VAScript

Status
Not open for further replies.

jimmyweb

Programmer
Dec 9, 2004
37
0
0
US
Hi friends,
I created a chart on the web by VBScript.
However, The Y [vertical line]does not display my enter value.But Y label display as 38059. It is not 0, 5, 10, 15.. {error in chDimSeriesNames or chDimValues?).Normally. the original point should be as 0.
Please help me to fix this issue.
**source codes
<%@ Language=VBScript %>
<HTML>
<head><title>calls chart example</title></head>
<STRONG><CENTER>Calls Per Day </CENTER></STRONG>

<BODY>
<object id=ChartSpace1 classid=CLSID:0002E500-0000-0000-C000-000000000046 style="width:100%;height:480"></object>
<object id=Spreadsheet1 classid=CLSID:0002E510-0000-0000-C000-000000000046 style="width:100%;height:480"></object>

<script language=vbs>
Sub Window_OnLoad()

class
Dim oSheet
Set oSheet = Spreadsheet1.ActiveSheet
oSheet.Cells.Clear
oSheet.Range("A2:A10").Value = Array("6/6/2005","6/7/2005","6/8/2005","6/9/2005","6/10/2005","6/11/2005","6/12/2005","6/13/2005","6/14/2005")
oSheet.Range("B1:B10").Value = Array("OBC", 0.3,0.07, 0.1,0.4,0.08,0.2,0.2,0.5,2.5)

Dim oChart
ChartSpace1.Clear
Set oChart = ChartSpace1.Charts.Add

' Set the Spreadsheet component as the data source for the chart
ChartSpace1.DataSource = Spreadsheet1

dim c
set c = ChartSpace1.Constants

'Add the data to the chart and set the series names
dim oSeries

for i=1 to 1
Set oSeries = oChart.SeriesCollection.Add
oSeries.SetData c.chDimValues, 0, oSheet.Range(oSheet.Cells(2,1), oSheet.Cells(10,1)).Address
oSeries.SetData c.chDimSeriesNames, 0, oSheet.Cells(1,1).Address
next

oChart.SetData c.chDimCategories, 0, "a2:a10"

oChart.Axes(c.chAxisPositionLeft).NumberFormat = "0"
oChart.Axes(c.chAxisPositionLeft).MajorUnit = 0.5

End Sub
</script>


</BODY>
</HTML>

****
 
If it is only the format problem, it is this.
>[tt]oChart.Axes(c.chAxisPositionLeft).NumberFormat = "0"[/tt]
[tt]oChart.Axes(c.chAxisPositionLeft).NumberFormat = [red]"m/d/yyyy"[/red][/tt]
Or you have different choices such as "mmm d,yyyy" etc following the same construction.

 
Probably you are pointing the y dim values to the wrong column.
>[tt]oSeries.SetData c.chDimValues, 0, oSheet.Range(oSheet.Cells(2,1), oSheet.Cells(10,1)).Address[/tt]
Should be this.
[tt]oSeries.SetData c.chDimValues, 0, oSheet.Range(oSheet.Cells(2,[red]2[/red]), oSheet.Cells(10,[red]2[/red])).Address[/tt]
 
Hi Tsuji and friends,
Thanks for your help!!
After changed to oSeries.SetData c.chDimValues, 0, oSheet.Range(oSheet.Cells(2,2), oSheet.Cells(10,2)).Address

It works and cut off 38058 at original point. But it have another issue. From original point. It display as 0. 1, 1, 2, 2, 3, 3, 4, 4, ..
It duplicated lable value? How to cut off this duplicated Y lable value?
I try to change chDimSeriesNames to 1,2 but it does not working.
Thanks for any help!!!

Jimmy
****new source code
source codes
<%@ Language=VBScript %>
<HTML>
<head><title>calls chart example</title></head>
<STRONG><CENTER>Calls Per Day </CENTER></STRONG>

<BODY>
<object id=ChartSpace1 classid=CLSID:0002E500-0000-0000-C000-000000000046 style="width:100%;height:480"></object>
<object id=Spreadsheet1 classid=CLSID:0002E510-0000-0000-C000-000000000046 style="width:100%;height:480"></object>

<script language=vbs>
Sub Window_OnLoad()

class
Dim oSheet
Set oSheet = Spreadsheet1.ActiveSheet
oSheet.Cells.Clear
oSheet.Range("A2:A10").Value = Array("6/6/2005","6/7/2005","6/8/2005","6/9/2005","6/10/2005","6/11/2005","6/12/2005","6/13/2005","6/14/2005")
oSheet.Range("B1:B10").Value = Array("OBC", 0.3,0.07, 0.1,0.4,0.08,0.2,0.2,0.5,2.5)

Dim oChart
ChartSpace1.Clear
Set oChart = ChartSpace1.Charts.Add

' Set the Spreadsheet component as the data source for the chart
ChartSpace1.DataSource = Spreadsheet1

dim c
set c = ChartSpace1.Constants

'Add the data to the chart and set the series names
dim oSeries

for i=1 to 1
Set oSeries = oChart.SeriesCollection.Add
oSeries.SetData c.chDimValues, 0, oSheet.Range(oSheet.Cells(2,2), oSheet.Cells(10,2)).Address

oSeries.SetData c.chDimSeriesNames, 0, oSheet.Cells(1,1).Address
next

oChart.SetData c.chDimCategories, 0, "a2:a10"

oChart.Axes(c.chAxisPositionLeft).NumberFormat = "0"
oChart.Axes(c.chAxisPositionLeft).MajorUnit = 0.5

End Sub
</script>


</BODY>
</HTML>
 
>It display as 0. 1, 1, 2, 2, 3, 3, 4, 4, ..
>[tt]oChart.Axes(c.chAxisPositionLeft).NumberFormat = "0"[/tt]
Change to this.
[tt]oChart.Axes(c.chAxisPositionLeft).NumberFormat = "0[red].0[/red]"[/tt]
if you want one decimal point, two "0.00" etc.

 
Hi Tsuji,

Thanks for your help!! great. It works well.
Again, Tsuji. Appreciated your help!!

Jim
 
Glad it works, Jim. I don't know..., maybe you have had commented out the line class or it involves some other part of the script. It is spurious here and can cause page error.
 
Hi tsuji and friends,
Thanks for your email.
other question.
Could I change X lable valus display as 5 day interval.
such 6/31/2005,7/5/2005,7/10/2005,7/15/2005....
The Y lable valus display interval and format are controled by below syntax
oChart.Axes(c.chAxisPositionLeft).NumberFormat = "0"
oChart.Axes(c.chAxisPositionLeft).MajorUnit = 0.5

How about X lable ?

Nice weekend

Thank again

Jim
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top