How to display text in the format hh:mm for a category label?

G

gregg100

I have the following html page, in which I need to display category labels in
the format hh:mm.

In order to do so, I currently need to add an extra character to at least
one of the category values to get it to work, such as an exclamation point,
or a tic.

for example: categories(0) = "!11:22"

The chart below currently does display.
I would like not to have to add the extra character.
If I remove the extra character, then the chart does not display.

Is there a way to display text in the format "hh:mm" for a category label?


<HTML>
<object id=ChartSpace1 classid=CLSID:0002E55D-0000-0000-C000-000000000046
style="width:100%;height:350"></object>

<script language=vbs>
Sub Window_OnLoad()

Dim categories(3)
Dim values(3)
Dim chConstants

' Create an array of strings representing the categories.

' The first category has a leading tic mark - without a character
' of some sort in one of the category values, the chart will not display
' The chart object cannot handle a string in the format xx:yy
categories(0) = "!11:22"
categories(1) = "11:33"
categories(2) = "11:44"
categories(3) = "11:45"

' Clear the contents of the chart workspace. This removes
' any old charts that may already exist and leaves the chart workspace
' completely empty. One chart object is then added.
ChartSpace1.Clear
ChartSpace1.Charts.Add
Set chConstants = ChartSpace1.Constants
ChartSpace1.Charts(0).Type = chConstants.chChartTypeSmoothLine

' Add one series to the chart.
ChartSpace1.Charts(0).SeriesCollection.Add

' Series one contains sales growth data for 1998.
' Set the series caption (the text that appears in the legend).
ChartSpace1.Charts(0).SeriesCollection(0).Caption = "10-Jun-1998"

' Set the categories for the first series (this collection is zero-based)
ChartSpace1.Charts(0).SeriesCollection(0).SetData
chConstants.chDimCategories, chConstants.chDataLiteral, categories

values(0) = 0.2
values(1) = 0.06
values(2) = 0.17
values(3) = 0.13

ChartSpace1.Charts(0).SeriesCollection(0).SetData
chConstants.chDimValues, chConstants.chDataLiteral, values

' Make the chart legend visible, format the left value axis as percentage,
' and specify that value gridlines are at 10% intervals.
ChartSpace1.Charts(0).HasLegend = True
ChartSpace1.Charts(0).Axes(chConstants.chAxisPositionLeft).NumberFormat
= "0%"
ChartSpace1.Charts(0).Axes(chConstants.chAxisPositionLeft).MajorUnit = 0.1

End Sub
</script>
</HTML>
 
G

gregg100

When I remove the additional character (!) in the categories(0) value, and
try


ChartSpace1.Charts(0).Axes(chConstants.chAxisPositionBottom).NumberFormat =
"hh:mm"

I get no graph line and "00:00" on the bottom axis.



Alvin Bruney said:
have you tried using an appropriate number format on the category label?

--
________________________
Warm regards,
Alvin Bruney [MVP ASP.NET]

[Shameless Author plug]
Professional VSTO.NET - Wrox/Wiley
The O.W.C. Black Book with .NET
www.lulu.com/owc, Amazon
Blog: http://www.msmvps.com/blogs/alvin
-------------------------------------------------------


gregg100 said:
I have the following html page, in which I need to display category labels
in
the format hh:mm.

In order to do so, I currently need to add an extra character to at least
one of the category values to get it to work, such as an exclamation
point,
or a tic.

for example: categories(0) = "!11:22"

The chart below currently does display.
I would like not to have to add the extra character.
If I remove the extra character, then the chart does not display.

Is there a way to display text in the format "hh:mm" for a category label?


<HTML>
<object id=ChartSpace1 classid=CLSID:0002E55D-0000-0000-C000-000000000046
style="width:100%;height:350"></object>

<script language=vbs>
Sub Window_OnLoad()

Dim categories(3)
Dim values(3)
Dim chConstants

' Create an array of strings representing the categories.

' The first category has a leading tic mark - without a character
' of some sort in one of the category values, the chart will not
display
' The chart object cannot handle a string in the format xx:yy
categories(0) = "!11:22"
categories(1) = "11:33"
categories(2) = "11:44"
categories(3) = "11:45"

' Clear the contents of the chart workspace. This removes
' any old charts that may already exist and leaves the chart workspace
' completely empty. One chart object is then added.
ChartSpace1.Clear
ChartSpace1.Charts.Add
Set chConstants = ChartSpace1.Constants
ChartSpace1.Charts(0).Type = chConstants.chChartTypeSmoothLine

' Add one series to the chart.
ChartSpace1.Charts(0).SeriesCollection.Add

' Series one contains sales growth data for 1998.
' Set the series caption (the text that appears in the legend).
ChartSpace1.Charts(0).SeriesCollection(0).Caption = "10-Jun-1998"

' Set the categories for the first series (this collection is
zero-based)
ChartSpace1.Charts(0).SeriesCollection(0).SetData
chConstants.chDimCategories, chConstants.chDataLiteral, categories

values(0) = 0.2
values(1) = 0.06
values(2) = 0.17
values(3) = 0.13

ChartSpace1.Charts(0).SeriesCollection(0).SetData
chConstants.chDimValues, chConstants.chDataLiteral, values

' Make the chart legend visible, format the left value axis as
percentage,
' and specify that value gridlines are at 10% intervals.
ChartSpace1.Charts(0).HasLegend = True
ChartSpace1.Charts(0).Axes(chConstants.chAxisPositionLeft).NumberFormat
= "0%"
ChartSpace1.Charts(0).Axes(chConstants.chAxisPositionLeft).MajorUnit =
0.1

End Sub
</script>
</HTML>
 
A

Alvin Bruney [MVP]

It turns out that this is a bug in the Office Web Components. The version I
have tested is OWC 11 on VS 2005.

The workaround I have is to add a dummy category to the data set since it is
the last value in the category that trips the chart. This is my fix.

Dim categories(4) 'add dummy place holder

categories(0) = "11:22"

categories(1) = "11:33"

categories(2) = "11:44"

categories(3) = "11:45"

categories(4) = "" 'place holder or a valid value without the semicolon will
also work such as 12

That's the best I can do here.


--
________________________
Warm regards,
Alvin Bruney [MVP ASP.NET]

[Shameless Author plug]
Professional VSTO.NET - Wrox/Wiley
The O.W.C. Black Book with .NET
www.lulu.com/owc, Amazon
Blog: http://www.msmvps.com/blogs/alvin
-------------------------------------------------------


gregg100 said:
When I remove the additional character (!) in the categories(0) value,
and
try


ChartSpace1.Charts(0).Axes(chConstants.chAxisPositionBottom).NumberFormat
=
"hh:mm"

I get no graph line and "00:00" on the bottom axis.



Alvin Bruney said:
have you tried using an appropriate number format on the category label?

--
________________________
Warm regards,
Alvin Bruney [MVP ASP.NET]

[Shameless Author plug]
Professional VSTO.NET - Wrox/Wiley
The O.W.C. Black Book with .NET
www.lulu.com/owc, Amazon
Blog: http://www.msmvps.com/blogs/alvin
-------------------------------------------------------


gregg100 said:
I have the following html page, in which I need to display category
labels
in
the format hh:mm.

In order to do so, I currently need to add an extra character to at
least
one of the category values to get it to work, such as an exclamation
point,
or a tic.

for example: categories(0) = "!11:22"

The chart below currently does display.
I would like not to have to add the extra character.
If I remove the extra character, then the chart does not display.

Is there a way to display text in the format "hh:mm" for a category
label?


<HTML>
<object id=ChartSpace1
classid=CLSID:0002E55D-0000-0000-C000-000000000046
style="width:100%;height:350"></object>

<script language=vbs>
Sub Window_OnLoad()

Dim categories(3)
Dim values(3)
Dim chConstants

' Create an array of strings representing the categories.

' The first category has a leading tic mark - without a character
' of some sort in one of the category values, the chart will not
display
' The chart object cannot handle a string in the format xx:yy
categories(0) = "!11:22"
categories(1) = "11:33"
categories(2) = "11:44"
categories(3) = "11:45"

' Clear the contents of the chart workspace. This removes
' any old charts that may already exist and leaves the chart
workspace
' completely empty. One chart object is then added.
ChartSpace1.Clear
ChartSpace1.Charts.Add
Set chConstants = ChartSpace1.Constants
ChartSpace1.Charts(0).Type = chConstants.chChartTypeSmoothLine

' Add one series to the chart.
ChartSpace1.Charts(0).SeriesCollection.Add

' Series one contains sales growth data for 1998.
' Set the series caption (the text that appears in the legend).
ChartSpace1.Charts(0).SeriesCollection(0).Caption = "10-Jun-1998"

' Set the categories for the first series (this collection is
zero-based)
ChartSpace1.Charts(0).SeriesCollection(0).SetData
chConstants.chDimCategories, chConstants.chDataLiteral, categories

values(0) = 0.2
values(1) = 0.06
values(2) = 0.17
values(3) = 0.13

ChartSpace1.Charts(0).SeriesCollection(0).SetData
chConstants.chDimValues, chConstants.chDataLiteral, values

' Make the chart legend visible, format the left value axis as
percentage,
' and specify that value gridlines are at 10% intervals.
ChartSpace1.Charts(0).HasLegend = True

ChartSpace1.Charts(0).Axes(chConstants.chAxisPositionLeft).NumberFormat
= "0%"
ChartSpace1.Charts(0).Axes(chConstants.chAxisPositionLeft).MajorUnit
=
0.1

End Sub
</script>
</HTML>
 
G

gregg100

Thank you for the determination that this is a bug - I did not know if I was
doing something wrong.

I tried the workaround, but I don't like to extra blank space at the end of
the chart.
While dinking with this, I tried using a period to replace the colon on the
first category value and that seems to have less visual impact.

categories(0) = "11.22"

Since we have to do a workaround, I'll go with the period - it is almost an
unreadable difference.

Thank you very much for your help!
PS. I ordered the book yesterday, since you took time to help me out.




Alvin Bruney said:
It turns out that this is a bug in the Office Web Components. The version I
have tested is OWC 11 on VS 2005.

The workaround I have is to add a dummy category to the data set since it is
the last value in the category that trips the chart. This is my fix.

Dim categories(4) 'add dummy place holder

categories(0) = "11:22"

categories(1) = "11:33"

categories(2) = "11:44"

categories(3) = "11:45"

categories(4) = "" 'place holder or a valid value without the semicolon will
also work such as 12

That's the best I can do here.


--
________________________
Warm regards,
Alvin Bruney [MVP ASP.NET]

[Shameless Author plug]
Professional VSTO.NET - Wrox/Wiley
The O.W.C. Black Book with .NET
www.lulu.com/owc, Amazon
Blog: http://www.msmvps.com/blogs/alvin
-------------------------------------------------------


gregg100 said:
When I remove the additional character (!) in the categories(0) value,
and
try


ChartSpace1.Charts(0).Axes(chConstants.chAxisPositionBottom).NumberFormat
=
"hh:mm"

I get no graph line and "00:00" on the bottom axis.



Alvin Bruney said:
have you tried using an appropriate number format on the category label?

--
________________________
Warm regards,
Alvin Bruney [MVP ASP.NET]

[Shameless Author plug]
Professional VSTO.NET - Wrox/Wiley
The O.W.C. Black Book with .NET
www.lulu.com/owc, Amazon
Blog: http://www.msmvps.com/blogs/alvin
-------------------------------------------------------


I have the following html page, in which I need to display category
labels
in
the format hh:mm.

In order to do so, I currently need to add an extra character to at
least
one of the category values to get it to work, such as an exclamation
point,
or a tic.

for example: categories(0) = "!11:22"

The chart below currently does display.
I would like not to have to add the extra character.
If I remove the extra character, then the chart does not display.

Is there a way to display text in the format "hh:mm" for a category
label?


<HTML>
<object id=ChartSpace1
classid=CLSID:0002E55D-0000-0000-C000-000000000046
style="width:100%;height:350"></object>

<script language=vbs>
Sub Window_OnLoad()

Dim categories(3)
Dim values(3)
Dim chConstants

' Create an array of strings representing the categories.

' The first category has a leading tic mark - without a character
' of some sort in one of the category values, the chart will not
display
' The chart object cannot handle a string in the format xx:yy
categories(0) = "!11:22"
categories(1) = "11:33"
categories(2) = "11:44"
categories(3) = "11:45"

' Clear the contents of the chart workspace. This removes
' any old charts that may already exist and leaves the chart
workspace
' completely empty. One chart object is then added.
ChartSpace1.Clear
ChartSpace1.Charts.Add
Set chConstants = ChartSpace1.Constants
ChartSpace1.Charts(0).Type = chConstants.chChartTypeSmoothLine

' Add one series to the chart.
ChartSpace1.Charts(0).SeriesCollection.Add

' Series one contains sales growth data for 1998.
' Set the series caption (the text that appears in the legend).
ChartSpace1.Charts(0).SeriesCollection(0).Caption = "10-Jun-1998"

' Set the categories for the first series (this collection is
zero-based)
ChartSpace1.Charts(0).SeriesCollection(0).SetData
chConstants.chDimCategories, chConstants.chDataLiteral, categories

values(0) = 0.2
values(1) = 0.06
values(2) = 0.17
values(3) = 0.13

ChartSpace1.Charts(0).SeriesCollection(0).SetData
chConstants.chDimValues, chConstants.chDataLiteral, values

' Make the chart legend visible, format the left value axis as
percentage,
' and specify that value gridlines are at 10% intervals.
ChartSpace1.Charts(0).HasLegend = True

ChartSpace1.Charts(0).Axes(chConstants.chAxisPositionLeft).NumberFormat
= "0%"
ChartSpace1.Charts(0).Axes(chConstants.chAxisPositionLeft).MajorUnit
=
0.1

End Sub
</script>
</HTML>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top