Wrox Programmer Forums
|
Excel VBA Discuss using VBA for Excel programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Excel VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 17th, 2003, 07:26 AM
Registered User
 
Join Date: Jun 2003
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Data Labels on Graphs

Hi All

I have a program that loads the data sources of pivot tables then copies the data pastes it into another worksheet then creates a graph on that worksheet from the data pasted. It then reloads the pivot table with the next data type and the process is repeated. The trouble is some data fields contain zero values and others dont. If I leave these zero values out the colors on the key change per data field per graph. therefore it is neccesaary for the zero's to be present. WHen I come to plot the graphs I need to show the percentage as a datalabel. This works fine for the data with values but the zero percents are also showing up on my graphs. Is there any way of hiding or getting rid off these programmatically. I need to plot 1500 graphs programmatically so It would be a hard task to carry out manually..


I have tried the following code but to no avail



    For Each ActiveChart.SeriesCollection(1).Points In Selection
    ActiveChart.SeriesCollection(1).Point.Select
    If ActiveChart.SeriesCollection(1).Points.Value = 0 Then
    Selection.Delete
    End If

Hope Some one can help many thanks
Jamie
 
Old June 18th, 2003, 10:00 AM
Registered User
 
Join Date: Jun 2003
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

The appended snippet is from a chart-plotting routine I use.
If the technology is working, the significant bit should be marked up in red and emboldened...
Crucially, to get a blank, you have to activate the label and blank it. I guess you can use any test you like: my problem was an incomplete data set (xVals) where the entry might be zero or simply left empty.
Hope there is something here which you can use.

Alf

  ' For each cell in the range xVals...
    For Each xCell In Range(xVals)
        On Error GoTo ErrorHandler
        [red]If IsEmpty(xCell) = True Or xCell = "0" Then
            ActiveChart.SeriesCollection(1).Points(Counter).Ha sDataLabel = True
            ActiveChart.SeriesCollection(1).Points(Counter).Da taLabel.Text = ""[/
            red] GoTo SkipBlankValue 'skip empty cells

        End If

        If xCell.Offset(0, SetOff) = "" Or xCell.Offset(0, SetOff) = "0" Then
            ActiveChart.SeriesCollection(1).Points(Counter).Ha sDataLabel = True
            ActiveChart.SeriesCollection(1).Points(Counter).Da taLabel.Text = ""

            GoTo SkipBlankValue
        End If



        ' Get the value of the label next to the current x-value.
        xLabel = Left$(xCell.Offset(0, -1).Value, 1) & Left$(xCell.Offset(0, -2).Value, 1)

        ' Attach a label to the current data point in the chart.
        Sheets(ThisChart).Activate
        ActiveChart.SeriesCollection(1).Points(Counter).Ha sDataLabel = True

        ' Put the text (initials) into the attached
        ' label.
        ActiveChart.SeriesCollection(1).Points(Counter).Da taLabel.Text = xLabel
SkipBlankValue:
        ' Increment the counter.
        Counter = Counter + 1

    Next xCell 'loop until all done
 
Old November 3rd, 2003, 02:09 PM
Registered User
 
Join Date: Nov 2003
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

WOuld this work labeling the X axis? I would like to graph the X axis using one column and label the points with another column(same rows).





Similar Threads
Thread Thread Starter Forum Replies Last Post
Export Data to Excel & Generate Graphs vinod_pawar1 ASP.NET 1.0 and 1.1 Professional 3 July 15th, 2006 01:03 AM
Generate all possible graphs mehdi62b C++ Programming 3 October 6th, 2004 03:28 PM
Transforming data and same labels in source table riuryK SQL Server DTS 1 April 5th, 2004 05:18 PM
dynamic graphs starlit Classic ASP Databases 1 February 11th, 2004 08:05 AM
Graphs jieli1001 ASP.NET 1.0 and 1.1 Professional 4 August 1st, 2003 06:23 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.