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!

Legend propery for MS Charts

Status
Not open for further replies.

gtroiano

Technical User
Nov 7, 2001
99
0
0
US
does anyone know how to change the legend through code. i found one thread that makes reference to the Legend property but i can't seem to get it to work. not to mention that the microsoft help sucks.

jerry.
 
in Access open VBE. Click Tools > References. Scroll down and pick Microsoft Graph x.x Project Library. Click OK.
Still in VBE open the Object Browser. In the first drop down pick "graph", click on the class you are interested in and then click the question mark to the right.

some examples found

myChart.Legend.Font.Bold = True
myChart.HasLegend = True
myChart.Legend.Font.ColorIndex = 5
myChart.Legend.LegendEntries(1).Font.Name = "Arial"


 
i don't know if it matters but "Microsoft Graph x.x Project Library" isn't listed. i do have "Microsoft Graph 9.0 Object Library" though. when i select this, it still doesn't work. i get the run-time error #438 - "Object doesn't support this property or method". any ideas?

jerry.
 
anyone have any other ideas?

jerry.
 
x.x meant I couldn't tell what version you had.

I have 9.0 as well and it works. I have a chart on a form called mychart. I have a button with the onclick event like

Private Sub Command1_Click()

mychart.Legend.Font.Bold = True
mychart.HasLegend = True
mychart.Legend.Font.ColorIndex = 5
mychart.Legend.LegendEntries(1).Font.Name = "Arial"

End Sub

What methods or properties are you trying to change and how are you changing them? Post some code maybe that will help.





 
i was hoping to change the labels in the legend.
you indicated "Microsoft Graph 9.0 Project Library" mine says: "Microsoft Graph 9.0 Object Library". i'm not sure if this matters. regardless, i can't even change the font, the font weight, or the visible properties for the legend as you previously posted.

jerry.
 
Sorry it's object not project. Double check that it's got a check next to it and has floated up with the rest of the selected refs.

I can send a small test mdb.

 
it's checked and at the top of the references. still doesn't work. a test db would be great. my email address is larrylipton@hotmail.com
thanks for the help.

jerry.
 
ok. i got the sample and it works fine. i'm trying to use the legend propery on a report as opposed to a form as you have showed me. so now i can get it to work on a form in my database but not on a report. [curse]

jerry.
 
Reports are funny that way as you have to do your coding before it gets formatted for print.

What event did you try to put the code under?

I saved my form as a report then put the same code under the Detail Event On Format and it worked.
 
hey. i have it working in the on format event of the report. i am looking for a way to change the labels in the legend through code. for example, on a bar graph, have the two years represented change. is this possible? does anyone know of a good site to reference chart?

jerry.
 
According to VB Help om LegendEntry Objects ...

"You cannot change the text of a legend entry. LegendEntry objects support font formatting, and they can be deleted."
 
i guess that answers that question. anyway, thanks a lot for your help.

jerry.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top