PDA

View Full Version : How: to check whether an element in chart is exist or not



yurble_vn
08-26-2007, 03:46 AM
Hi All,

I use the following code to select a Point Lable in chart. but whenever there is no label exist, this will go to error. So, is there anyway to check the element exist before select?

Thanks


ActiveChart.SeriesCollection(iSeries).Points(Datapoint).DataLabel.Select

p45cal
08-26-2007, 06:16 AM
You could tryOn Error Resume Next
y = ActiveChart.SeriesCollection(ISeries).Points(DataPoint).DataLabel.Text
If Err = 0 Then DataLabelExists = True Else DataLabelExists = False
On Error GoTo 0
If DataLabelExists Then ActiveChart.SeriesCollection(ISeries).Points(DataPoint).DataLabel.Select

p45cal
08-26-2007, 06:24 AM
Siily me:
If ActiveChart.SeriesCollection(ISeries).Points(DataPoint).HasDataLabel Then ActiveChart.SeriesCollection(ISeries).Points(DataPoint).DataLabel.Select

yurble_vn
08-26-2007, 06:28 AM
Great..., thanks P45cal,

Can I apply the HasDataLabel to all orther object? What is the keyword (Programning call ) to seek it. SO I can seek for next time.

p45cal
08-26-2007, 06:44 AM
No I don't think so. I just came across it after my first post.

yurble_vn
08-26-2007, 07:02 AM
By the way, is there anyway to get the datapoint value?

yurble_vn
08-26-2007, 07:48 AM
Let I say in more details,

What I trying to do is: in a line chart, there are two line and value labeled. So, sometime, if the value of two line is too close, the label of the two line will be overlaped. So, if I can get the data point value, I can check whelther they are too close or not and modify the position...

Thanks

p45cal
08-26-2007, 10:48 AM
Well, while playing I found that it is difficult if not impossible to adjust the value of a point with the likes of
ActiveChart.SeriesCollection(iSeries).Values(DataPoint)=3.567This would only make sense if the value in the range that the chart gets its values from was also adjusted (this happens when you graphically (with the mouse) adjust a point on a chart).
I could only find a way of reading the values by the likes of:
DataPoint = 6
ActiveSheet.ChartObjects("Chart 1").Activate
p = ActiveChart.SeriesCollection(1).Values
MsgBox p(DataPoint)
I think the only vba way to adjust a point is to determine which cell it's plotting and adjust that value.

yurble_vn
08-26-2007, 10:54 AM
NO, I'm not trying to adjust the point values,

What I trying is from the point value, I calculate the label position...