How to color points on xy chart based upon another series

TeeChart for ActiveX, COM and ASP
amueller
Newbie
Newbie
Posts: 30
Joined: Tue Jul 26, 2005 4:00 am

How to color points on xy chart based upon another series

Post by amueller » Thu Oct 13, 2005 2:35 pm

Hello,

I have 2 series on a chart.. (Visual Basic). One series is an scMap which is an area of the chart which represents 'good' data.

I have another series that will be created from semi-realtime data (database updated from a realtime source).

I would like to be able to:

Add a Point, check if it lies WITHIN the scMap series, and then color the point based upon that.

I am having a difficult time with it, though... Any ideas??

Thanks!

Andrew

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Post by Narcís » Thu Oct 13, 2005 3:13 pm

Hi Andrew,

You can try using locate method to see if the point value has a valid index (different from -1) in the map series. You can use this method doing something like:

Code: Select all

Dim tmp As Integer

  tmp = TChart1.Series( 0 ).XValues.Locate(DateValue("1996,9,1"))
  If tmp <> -1 Then
    MsgBox (Str$(TChart1.Series( 0 ).YValues.Value(tmp)))
  End If
Best Regards,
Narcís Calvet / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

amueller
Newbie
Newbie
Posts: 30
Joined: Tue Jul 26, 2005 4:00 am

Post by amueller » Thu Oct 13, 2005 3:29 pm

I tried that, but except for 0, it is always -1. Here are the points:

scMap
-------

With TChart1

.AddSeries scMap
.Series(0).asMap.Shapes.Add
.Series(0).asMap.Shapes.Polygon(0).Transparency = 80
.Series(0).asMap.Shapes.Polygon(0).Color = vbGreen
.Series(0).asMap.Shapes.Polygon(0).AddXY 0, 4.99
.Series(0).asMap.Shapes.Polygon(0).AddXY 1, 5.02
.Series(0).asMap.Shapes.Polygon(0).AddXY 2, 5.05
.Series(0).asMap.Shapes.Polygon(0).AddXY 3, 5.09
.Series(0).asMap.Shapes.Polygon(0).AddXY 11, 5.12
.Series(0).asMap.Shapes.Polygon(0).AddXY 11, 5.25
.Series(0).asMap.Shapes.Polygon(0).AddXY 3, 5.13
.Series(0).asMap.Shapes.Polygon(0).AddXY 2, 5.09
.Series(0).asMap.Shapes.Polygon(0).AddXY 1, 5.04
.Series(0).asMap.Shapes.Polygon(0).AddXY 0, 5.03

.Legend.Visible = False

.Axis.Bottom.Minimum = 0
.Axis.Bottom.Maximum = 11
.Axis.Bottom.Increment = 1
.Axis.Bottom.Title.Caption = "Setting"

.Axis.Left.Minimum = 4.98
.Axis.Left.Maximum = 5.25
.Axis.Left.Increment = 0.03
.Axis.Left.Title.Caption = "Average Fill Mass (mg) - 5.1 mg Lots"


End With


asPoint
--------

With TChart1
.AddSeries scPoint
TestLimits 0, 5.01
TestLimits 0.3, 5.05
TestLimits 1, 5.01
TestLimits 1.5, 5.07
TestLimits 2, 5.11
TestLimits 2.8, 5.13
TestLimits 3, 5.1
TestLimits 3.5, 5.09
TestLimits 4, 5.16
TestLimits 4.8, 5.15
TestLimits 5, 5.13
TestLimits 6, 5.1
TestLimits 6.2, 5.11
TestLimits 6.7, 5.17
TestLimits 7, 5.15
TestLimits 8, 5.2
TestLimits 8.1, 5.22
TestLimits 9, 5.19
TestLimits 9.6, 5.2
TestLimits 10, 5.23
TestLimits 10.8, 5.25
End With


When trying the code you posted, I always get a -1 for tmp... Here is the code (very slightly modified):

Private Sub TestLimits(X As Double, Y As Double)

Dim tmp As Integer

With TChart1

tmp = TChart1.Series(0).XValues.Locate(X)

If tmp <> -1 Then
Debug.Print "YValue:: " & Str$(TChart1.Series(0).YValues.Value(tmp))
Debug.Print "XValue:: " & X
End If

If (TChart1.Series(0).YValues.Value(tmp) < Y) Then
.Series(1).AddXY X, Y, "", RGB(33, 0, 0)
Else
.Series(1).AddXY X, Y, "", RGB(33, 33, 33)
End If
End With

End Sub

amueller
Newbie
Newbie
Posts: 30
Joined: Tue Jul 26, 2005 4:00 am

Post by amueller » Fri Oct 14, 2005 9:33 pm

bump.

amueller
Newbie
Newbie
Posts: 30
Joined: Tue Jul 26, 2005 4:00 am

Post by amueller » Mon Oct 17, 2005 1:16 pm

Well.... Nothing I have tried seems to work. I wouldn't think that this would be a difficult task, but it is proving to be very difficult and I am spending a ton of time on it.

Can anyone help??

TTL
Newbie
Newbie
Posts: 36
Joined: Thu Aug 04, 2005 4:00 am

Post by TTL » Mon Oct 17, 2005 1:19 pm

Hello,

Very interesting question :-) If there's an answer, I would like to know it too. Locate won't work because it tries to find the exact coordinate, not everything in between. Solution for now could be to have the "realtime source" indicate to database if the point is "good" or not. Then you can read that other column from database and paint the point accordingly.

Alex

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Post by Narcís » Mon Oct 17, 2005 2:13 pm

Hello everyone,

amueller, in your case Locate won't work for what Alex explains. If the points aren't the exactly the same, the code below works fine:

Code: Select all

Private Sub Form_Load()
    With TChart1
        .AddSeries scMap
        .Series(0).asMap.Shapes.Add
        .Series(0).asMap.Shapes.Polygon(0).Transparency = 80
        .Series(0).asMap.Shapes.Polygon(0).Color = vbGreen
        .Series(0).asMap.Shapes.Polygon(0).AddXY 0, 4.99
        .Series(0).asMap.Shapes.Polygon(0).AddXY 1, 5.02
        .Series(0).asMap.Shapes.Polygon(0).AddXY 2, 5.05
        .Series(0).asMap.Shapes.Polygon(0).AddXY 3, 5.09
        .Series(0).asMap.Shapes.Polygon(0).AddXY 11, 5.12
        .Series(0).asMap.Shapes.Polygon(0).AddXY 11, 5.25
        .Series(0).asMap.Shapes.Polygon(0).AddXY 3, 5.13
        .Series(0).asMap.Shapes.Polygon(0).AddXY 2, 5.09
        .Series(0).asMap.Shapes.Polygon(0).AddXY 1, 5.04
        .Series(0).asMap.Shapes.Polygon(0).AddXY 0, 5.03
        
        .Legend.Visible = False
        
        .Axis.Bottom.SetMinMax 0, 11
        .Axis.Bottom.Increment = 1
        .Axis.Bottom.Title.Caption = "Setting"
        
        .Axis.Left.SetMinMax 4.98, 5.25
        .Axis.Left.Increment = 0.03
        .Axis.Left.Title.Caption = "Average Fill Mass (mg) - 5.1 mg Lots"
        
        .Environment.InternalRepaint
    End With
    
    With TChart1
        .AddSeries scPoint
        TestLimits 0, 5.01
        TestLimits 0.3, 5.05
        TestLimits 1, 5.01
        TestLimits 1.5, 5.07
        TestLimits 2, 5.11
        TestLimits 2.8, 5.13
        TestLimits 3, 5.1
        TestLimits 3.5, 5.09
        TestLimits 4, 5.16
        TestLimits 4.8, 5.15
        TestLimits 5, 5.13
        TestLimits 6, 5.1
        TestLimits 6.2, 5.11
        TestLimits 6.7, 5.17
        TestLimits 7, 5.15
        TestLimits 8, 5.2
        TestLimits 8.1, 5.22
        TestLimits 9, 5.19
        TestLimits 9.6, 5.2
        TestLimits 10, 5.23
        TestLimits 10.8, 5.25
    End With
End Sub

Private Sub TestLimits(X As Double, Y As Double)
    Dim tmp, XCoord, YCoord As Integer
    
    With TChart1
        XCoord = .Axis.Bottom.CalcXPosValue(X)
        YCoord = .Axis.Left.CalcYPosValue(Y)
        
        tmp = .Series(0).Clicked(XCoord, YCoord)
        
        If tmp <> -1 Then
            Debug.Print "YValue:: " & Str$(.Series(0).YValues.Value(tmp))
            Debug.Print "XValue:: " & X
            .Series(1).AddXY X, Y, "", RGB(255, 0, 0)
        Else
            .Series(1).AddXY X, Y, "", RGB(0, 0, 255)
        End If
    End With
End Sub
Best Regards,
Narcís Calvet / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

amueller
Newbie
Newbie
Posts: 30
Joined: Tue Jul 26, 2005 4:00 am

Post by amueller » Mon Oct 17, 2005 10:00 pm

Thank you! That was exactly what I needed!

Andrew

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Post by Narcís » Tue Oct 18, 2005 7:53 am

Hi Andrew,

You're welcome. I'm glad we've finally found a solution suitable for your needs.
Best Regards,
Narcís Calvet / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

amueller
Newbie
Newbie
Posts: 30
Joined: Tue Jul 26, 2005 4:00 am

Post by amueller » Mon Jan 09, 2006 1:11 pm

I just wrapped up this project into an activeX control and am now having issues...

Basically,

The points will definitely change color based upon the asMap series when the code is in a 'Standard EXE' in VB6.

HOWEVER,

The points DO NOT change color based upon the asMap series when the code is set up as an activeX control. I have embedded the object in two different containers, 1 being VB itself in a 'Standard EXE' and both times I get the same result, doesn't work.

Please help!

Thanks,

Andrew

Pep
Site Admin
Site Admin
Posts: 3303
Joined: Fri Nov 14, 2003 5:00 am
Contact:

Post by Pep » Sun Jan 15, 2006 4:37 pm

Hi Andrew,

yes, you're correct, the problem is that the Clicked method was designed to be used in 2D, and having set a 3D percent the point is as it does not correspond with the shape. I'll add a new "PointInPolygon" for the next ActiveX maintenance releases.
In meantime a way to have correct results will be to check if the points fit in the shape in 2D mode, and then change the Chart to 3D.
In your app you could solve it just adding the following line at the top of the init method (load) :
.Aspect.View3D = False
and :
.Aspect.View3D = True
after all the TestLimits calls has been executed.

amueller
Newbie
Newbie
Posts: 30
Joined: Tue Jul 26, 2005 4:00 am

Post by amueller » Fri Jan 20, 2006 4:29 pm

Pep -

I gave that a try (sorry for the delay, got stuck on another project) and it still did not work.

I set the aspect to 3d prior to loading up the chart with the map series and the point series.

I then, at the end of the testlimits sub, set the aspec to 2d (false).

Still, all points are red (except of course the flashing point that I created)

Help!

thanks.

amueller
Newbie
Newbie
Posts: 30
Joined: Tue Jul 26, 2005 4:00 am

Post by amueller » Fri Jan 20, 2006 8:23 pm

Also... The chart is 2D anyway, so that is always the aspect for the chart.

The points just will not color based upon the map series. It will work fine if the code is part of a standard .exe file (with form). But this code will not work if I make this into an ActiveX control (wrap the Teechart into an activex control, suppress all the methods & properties, and add my dataadd method and ADO properties.

I can send you code if you like, but it is simple to reproduce from the above code. Just create an activex out of it, put it into a container (like a VB form in a standard exe) and you will see that the points no longer turn color.

Pep
Site Admin
Site Admin
Posts: 3303
Joined: Fri Nov 14, 2003 5:00 am
Contact:

Post by Pep » Tue Jan 24, 2006 8:10 am

Hi Andrew,

I've tried to create the ocx here using the trick I told you and it seems that works fine here. I've posted the ocx project and a sample project into the http://www.steema.net/steema.public.attachments newsgroups with the same subject, could you please check if it works fine for you ?
If you still having problems, please send me a simple demo sample with which I can reproduce the problem here, you can send me it to pep@steema.com

amueller
Newbie
Newbie
Posts: 30
Joined: Tue Jul 26, 2005 4:00 am

Post by amueller » Tue Jan 24, 2006 4:05 pm

Yours works fine on my machine. I put the same code into my control and it does not work. Maybe because of some of the properties I am setting, I don't know. Like I said, I could copy the whole activex code over into a standard exe, drop a tchart control on there and it works perfectly (with my code and with your code).

Maybe you could take a look at it. I'll post it soon to the newsgroup. I just have to remove my debugging code because it uses an activex debugger control.

Andrew

Post Reply