ASE Home Page Products Download Purchase Support About ASE
ChartDirector Support
Forum HomeForum Home   SearchSearch

Message ListMessage List     Post MessagePost Message

  Hide/Show Lines
Posted by Chuck on Feb-22-2020 04:58
Peter,

I have several lines per trading session that get programmatically created. How can I group these lines in order to show/hide the group (tied to a Checkbox for show/hide)? Grouping will be by Session and by Week, etc.

Thank you,
chuck

  Re: Hide/Show Lines
Posted by Peter Kwan on Feb-23-2020 18:42
Hi Chuck,

The Interactive Financial Chart sample code included in ChartDirector is an example that demonstrates how to show/hide a line with a checkbox. The code is like:

    If ParabolicSAR.Checked Then
        m.addParabolicSAR(0.02, 0.02, 0.2, Chart.DiamondShape, 5, &H008800, &H000000)
    End If

In the above, the "Parabolic SAR" indicator will appear only if the ParabolicSAR check box is checked.

If you want the checkbox to control multiple lines, just add multiple lines in the If/Then statement.

If myCheckBox.Checked Then
    .... add one line ....
    .... add another line ....
End If

Hope this can help.

Regards
Peter Kwan

  Re: Hide/Show Lines
Posted by Chuck on Feb-24-2020 02:52

Hi Peter,

Thank you for your reply.

My specific interest is how I might be able to set an attribute or property on a line, and then show/hide the entire group. Would this be possible? If so, a VB.NET example would be helpful.

Thank you for your continued help and support.
Chuck

  Re: Hide/Show Lines
Posted by Peter Kwan on Feb-25-2020 03:39
Hi Chuck,

You can hide/show the lines as a group by putting them inside an If/Then statement, like:

If myCheckBox.Checked Then
    c.addLineLayer(lineData1, lineColor1, lineName1)
    c.addLineLayer(lineData2, lineColor2, lineName2)
End If

Instead of adding the lines one by one, you can certainly use a loop if you like.

Suppose the following class is used to store your line configuration:

Class MyLineObject
    Public lineData As Double()
    Public lineColor As Integer
    Public lineName As String
End Class

You can group the lines by placing them in a List

Dim myLineGroup As New List(MyLineObject)

The code is then:

If myCheckBox.Checked Then
    For Each lineObj As MyLineObject in myLineGroup
        c.addLineLayer(lineObj.lineData, lineObj.lineColor, lineObj.lineName)
    Next
End If

Note that the only charting code above is c.addLineLayer(....), which adds a line on the chart. It is expected your code would add only things on the chart, but not things that is not on the chart.

Regards
Peter Kwan

  Re: Hide/Show Lines
Posted by Chuck on Feb-25-2020 04:05

Hi Peter,

Thank you for the quick VB tutorial... however, the scope of the question has to do with identifying the line via some property set at creation.

So, let’s say (using your example) that “LineNumberName” is an incrementing Integer used with every line sequentially created via an automated process... is there a way (within ChartDirector) that at the time of line creation I can set a property on the line that later can be used to group specific lines... where the For/Next Loop would Set the group for show/hide?

Although creating the (many) List collections is possible for each group, iterating through *all* lines via a property would be more compact.

Thank you!
Chuck

  Re: Hide/Show Lines
Posted by Peter Kwan on Feb-25-2020 12:32
Hi Chuck,

You mentioned you want to "hide/show" the lines. That means you want to change the chart.

In ChartDirector, the chart is changed by destroying the old chart and creating a new chart. You can "set a property at the time of line creation" on the ChartDirector chart object. But when you want to change the chart, the chart object (with all the line objects in it) is destroyed, so you cannot use the "property" this way. The new chart with have new line objects.

Also, in ChartDirector, the line is "hidden" by not creating it in the first place. So the line object is not even there.

That means the "Line" you need must be an object created by you, not ChartDirector. You can treat the property as part of your data. Your data must exist before creating the chart. The data must continue to exist after the old chart is destroyed, so they can be used to create a new chart.

' Your line object
Class MyLineObject
    Public lineData As Double()
    Public lineColor As Integer
    Public lineName As String
    Public lineNumberName As Integer
    Public groupProperty As String
End Class

Dim myLineGroup As New List(MyLineObject)

You can create many list collections or one list collection. You can always design your code to suit your needs. For example:

If myCheckBox.Checked Then
    For Each lineObj As MyLineObject in myLineGroup
        ' The myCheckBox controls the visibility of the group "ABC"
        If lineObj.groupProperty = "ABC" And Not myCheckBox.Checked Then
            Continue For
        End If
        ' You can add more code to specify which checkbox controls which group

       c.addLineLayer(lineObj.lineData, lineObj.lineColor, lineObj.lineName)
    Next
End If

In the above, the If/Then statement is just to configure which checkbox is for which group. In the above, the myCheckBox is a hard coded name. As mentioned above, you can always modify the code to suit your needs. If you want a dynamically created checkbox or other kind of user interface, you can always modify the code for to fit your needs.

Regards
Peter Kwan