Data Labels / Percents on Bar Charts

M

MePadre

I am trying to get my Bar Charts to show both the value
and the lable relative to the other bars on the graph. At
present, if I include percentages, I get 100% for each of
my bars. I would like to total of, say a 5 bar chart, to
amount to 100%.

I am using OWC from Office 2000.

Here is my code.

Response.Expires = -1
Response.ContentType = "image/gif"

Dim m_cn 'connection object
Dim m_rs 'Recordset object
Dim m_cspace 'OWC.ChartSpace object
Dim m_fso 'file system object
Dim m_objBinaryFile 'BinaryFileStream object
Dim sSQL 'SQL statement to execute
Dim c 'OWC Constants object
Dim cht 'Temp ref to a chart
Dim ax 'Temp ref to an axis
Dim fnt 'Temp ref to an OWCFont
Dim sFullFileName 'Full path to temp file for exported GIF

set m_cn = Server.CreateObject("ADODB.Connection")
set m_rs = Server.CreateObject("ADODB.Recordset")

m_cn.Open strconnect
sSQL = "SELECT chartType, chartHeight,
QuestionText,QuestionNumber,AnswerText AS [Answers], Count
AS [Values], answerNumber AS [Series] FROM
q_responseSummary WHERE questionID=" & request.querystring
("questionID")

m_rs.CursorLocation = 3 'adUseClient
m_rs.Open sSQL, m_cn, 3 'adOpenStatic

set m_cspace = server.CreateObject("OWC.Chart")
set cht = m_cspace.Charts.Add()
set c = m_cspace.Constants

' set the type of chart based on DB
IF m_rs("chartType") = 1 THEN ' COLUMN
cht.Type = c.chChartTypeColumnClustered
varShowAxis = true
varShowPercent = false
ELSEIF m_rs("chartType") = 2 THEN ' BAR
cht.Type = c.chChartTypeBarClustered
varShowAxis = true
varShowPercent = false
ELSEIF m_rs("chartType") = 3 THEN ' PIE
cht.Type = c.chChartTypePie
cht.HasLegend = True
varShowPercent = true
ELSE
cht.Type = c.chChartTypeColumnClustered ' DEFAULT
varShowAxis = true
varShowPercent = false
END IF

' cht.SetData c.chDimSeriesNames, 0, "Series"
cht.SetData c.chDimCategories, 0, "Answers"
cht.SetData c.chDimValues, 0, "Values"
cht.SeriesCollection(0).DataLabelsCollection.Add
cht.SeriesCollection(0).DataLabelsCollection(0).Font.Name
= "Arial"
cht.SeriesCollection(0).DataLabelsCollection(0).Font.Bold
= False
cht.SeriesCollection(0).DataLabelsCollection(0).Font.Size
= 8
cht.SeriesCollection(0).DataLabelsCollection(0).HasValue =
True

IF varShowPercent THEN cht.SeriesCollection
(0).DataLabelsCollection(0).HasPercentage = true

'add a chart title and format the title
cht.HasTitle = True
cht.Title.Caption = "Question #" & m_rs("questionNumber")
& " - " & m_rs("questionText")
set fnt = cht.Title.Font
fnt.Name = "Arial"
fnt.Size = 10
fnt.Bold = True


IF varShowAxis THEN

' add a title to the category axis/format the title
set ax = cht.Axes(c.chAxisPositionBottom)
ax.HasTitle = True
ax.Title.Caption = "Responses"
set fnt = ax.Title.Font
fnt.Name = "Arial"
fnt.Size = 8
fnt.Bold = True

'add a title to the value axis and format the title
set ax = cht.Axes(c.chAxisPositionLeft)
' ax.NumberFormat = "Currency"
ax.MajorUnit = 5
ax.HasTitle = True
ax.Title.Caption = "Number of Responses"
set fnt = ax.Title.Font
fnt.Name = "Arial"
fnt.Size = 8
fnt.Bold = True

END IF


'Save the current chart to a GIF file with a temporary,
unique filename
set m_fso = CreateObject("Scripting.FileSystemObject")
sFullFileName = server.mappath("./") & "\" &
m_fso.GetTempName()

varChartHeight = m_rs("chartHeight")
varChartWidth = 500


m_cspace.ExportPicture sFullFileName, "gif",
varChartWidth, varChartHeight

on error resume next ' ENSURE CHART GETS DELETED

set m_objBinaryFile = server.CreateObject
("BinaryFileStream.Object")
Response.BinaryWrite m_objBinaryFile.GetFileBytes(CStr
(sFullFileName))

'Delete the GIF file since it is no longer needed
m_objBinaryFile.DeleteFile CStr(sFullFileName)

m_rs.close
set m_rs = Nothing
m_cn.close
set m_cn = Nothing
 

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