Solved

MSChart Pie Chart - Data Labels

Posted on 1998-12-14
16
3,047 Views
Last Modified: 2013-12-26
I have managed to load data into a pie chart format using an MSChart control, but I have been unable to find a way to display % data labels for each pie slice. I am not using a DBgrid control at this moment, is this possibly the reason that I can't get labels? The DBgrid control was not necessary in order for me to display the pie chart data. Any suggestions would be greatly appreciated.
0
Comment
Question by:efowl
  • 6
  • 5
  • 3
  • +2
16 Comments
 
LVL 12

Expert Comment

by:mark2150
ID: 1488961
Give up on MSChart control. Is difficult to use and *CANNOT* PRINT!

I have working source for piecharts.

email me direct at Mark_Lambert@ntsc.navy.mil

M

0
 

Author Comment

by:efowl
ID: 1488962
Adjusted points to 200
0
 
LVL 1

Expert Comment

by:tommy_boy
ID: 1488963
That's crap, MSCHART can print, you just need to know how to do it.

Check the properties of the MSChart.  Also, are you displaying the Chart in 3d or 2d?  What is your data array? You do know that the first element (no of sections generally) needs to be a string, even if you want just numbers to appear.
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 1

Expert Comment

by:tommy_boy
ID: 1488964
That's crap, MSCHART can print, you just need to know how to do it.

Check the properties of the MSChart.  Also, are you displaying the Chart in 3d or 2d?  What is your data array? You do know that the first element (no of sections generally) needs to be a string, even if you want just numbers to appear.
0
 
LVL 12

Expert Comment

by:mark2150
ID: 1488965
Ok, Tommoy_boy, just *HOW* do *YOU* print the MSChart control? The !@#$%^ doesn't have a .Print method! Or do you just print a *picture* of the graph with the blockyness that comes with it?

M

0
 
LVL 1

Expert Comment

by:tommy_boy
ID: 1488966
Mark2150:

Briefly, a print a MSCHART you need to copy it's image (yes it is a bitmap, or similar) to the clipboard.  From there it is a simple matter of printing the contents of the clipboard (as a bitmap).
Try this:

  MSCHART1.EditCopy
  Printer.Print " "
  Printer.PaintPicture Clipboard.GetData(), 0, 0
  Printer.EndDoc

Best Regards

TB
0
 
LVL 12

Expert Comment

by:mark2150
ID: 1488967
The problem with the bitmap is that your text is rendered at the resolution of the screen object. When you put it down on paper it either comes out *tiny* but sharp, or Large and *UGLY*. I want the control to print with full fidelity so that my text legends don't look like a screen dump. There is *NO WAY* for that control to do this so instead of having my output look like a 4th graders I don't use the control. I generate my own graphing routines that render with full fidelity. Both my customers and myself prefer the quality level improvement that this provides.

Printing a form as a bitmap is a *kludge* and a "workaround" and *NOT* suitable for commercial ($$$$) code.

M

0
 

Author Comment

by:efowl
ID: 1488968
enough about printing I still need to know how to display data labels, it is not part of the properties that I can see of.
0
 
LVL 12

Expert Comment

by:mark2150
ID: 1488969
Again, the answer is to give up on the control. Once you start writing your own graph routine you can use .CurrentX and .CurrentY to position the cursor whereever you want. Then a .Print "this is my label" will allow you to put text whereever you need it. Text is always drawn down and to the right of your cursor position so you might need to use the .TextWidth("this is my label") property to determine how wide your string is and then adjust the .CurrentX accordingly.

M

0
 

Author Comment

by:efowl
ID: 1488970
I tried your sample code and could not get it to work. Is there possibly another VB control that has graphing capability.
0
 
LVL 12

Expert Comment

by:mark2150
ID: 1488971
You can graph to a picture box.

You want operational source?

Write me direct:

Mark_Lambert@ntsc.navy.mil

M

0
 

Expert Comment

by:Stephen_Miller
ID: 1488972
I would like to see mark2150 write code to render a clickable 3d graph as effortlessly as the MSChart control. Sure its poorly documented and some of its properties are esoteric
but why reinvent the wheel?

Meanwhile, back to efowl

Have you actualy entered labels for your chart?

with MSChart1
  '-- enter text
  For i = 1 to .ColCount
     .column = i
     .collabel = "your label here"
  next i
  For i = 1 to .RowCount
     .row = i
     .rowlabel = "your label here"
  next i
  '-- control legend
  .legend.location.visible = true
  .legend.location.locationtype = 8
  .legend.location.RECT.min.set Xval, Yval
  .legend.location.RECT.max.set Xval, Yval
end with
0
 

Author Comment

by:efowl
ID: 1488973
Yes, I have added row and column labels, as you defined, but to no avail. I do agree with your comment about MSCHART, I just wish it had all the bells and whistles, and I wish there was more documentation on it.
0
 

Author Comment

by:efowl
ID: 1488974
A microsoft support engineer has found the solution to my problem with the following code:

For i = 1 To mschart1.Plot.SeriesCollection.Count
With mschart1.Plot.SeriesCollection(i) &_
     .DataPoints(-1).DataPointLabel
.LocationType = VtChLabelLocationTypeOutside
.Component= VtChLabelComponentPercent
.PercentFormat = "0%"
.VtFont.Size = 10
End With
Next

...this will obtain pie chart data labels.

Thanks for everyone's input,
Eric
0
 

Author Comment

by:efowl
ID: 1488975
A microsoft support engineer has found the solution to my problem with the following code:

For i = 1 To mschart1.Plot.SeriesCollection.Count
With mschart1.Plot.SeriesCollection(i) &_
     .DataPoints(-1).DataPointLabel
.LocationType = VtChLabelLocationTypeOutside
.Component= VtChLabelComponentPercent
.PercentFormat = "0%"
.VtFont.Size = 10
End With
Next

...this will obtain pie chart data labels.

Thanks for everyone's input,
Eric
0
 
LVL 8

Accepted Solution

by:
vettranger earned 200 total points
ID: 1488976
I know you found an answer for that specific problem, but if you're going to use charts a LOT for varied purposes, the TeeChart control is inexpensive and gives you a lot of flixibility for graphs and labeling.
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Visual Basic Excel Formatting error 4 127
VB6 ListBox Question 4 48
Zip Folders Using Chilkat Routines 1 58
VB6 - Scroll Mouse wheel on Picturebox 13 70
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question