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

Message ListMessage List     Post MessagePost Message

  Coordinates of Lengend Entry for a data set
Posted by Karen A on Nov-08-2020 07:46
Looking at the docs it looks straight forward to get the location and size of a legend box on an XYChart, But is the way to get that info for the individual data set entries WITHIN the legend box? If there is, I am missing it. (or not understanding how legends work in CD).

That is something I would expect to exist as it seems to me, that it would not be that uncommon a need.

For a desktop app I am writing, I have an XYChart with multiple datasets with a legend box. I want to be able to perform an action for a specific dataset if the user clicks on it's legend entry.

As far as I can see, to do that I need the coordinates and size information for each entry in the legend box.

Either that or a method on the legend box that, given X,Y coordinates, will return the name  for the dataset  who's legend is at that location? (If that does not exist please consider that a feature request!)

Do either exist in CD?  If not, is there another way that already exists?

Thanks,
-Karen

  Re: Coordinates of Lengend Entry for a data set
Posted by Peter Kwan on Nov-09-2020 12:42
Hi Karen,

From your earlier post, it seems you are using VB as the programming language. Are you using ChartDirector for .NET and is your program a desktop of web application?

For web applications, there is already an example for "Custom Clickable Objects" at:

https://www.advsofteng.com/doc/cdnet.htm#customclickable.htm

Basically, the method is to use the image map for the LegendBox, obtained from LegendBox.getHTMLImageMap. This will turn the legend keys into "hot spots" that you can clicked on. This method also works for desktop applications.

Consider the "Simple Zooming and Scrolling" sample code:

In the original sample code, the image map only includes the data points and it is for including tooltips for the data points.

If IsNothing(winChartViewer1.ImageMap) Then
    winChartViewer1.ImageMap = winChartViewer1.Chart.getHTMLImageMap("", "", _
        "title='[{dataSetName}] {x|mmm dd, yyyy}: USD {value|2}'")
End If

You can add the image map for the legend box too:

If IsNothing(winChartViewer1.ImageMap) Then
    winChartViewer1.ImageMap = winChartViewer1.Chart.getHTMLImageMap("", "", _
        "title='[{dataSetName}] {x|mmm dd, yyyy}: USD {value|2}'") & _
        winChartViewer1.Chart.getLegend().getHTMLImageMap("clickable", "legend={dataSetName}")

    'Optional line to change to hand cursor when mouse is over a clickable hotspot
    winChartViewer.HotSpotCursor = Cursors.Hand
End If

Now you can attached a ClickHotSpot event handler to handle the click event and identify which legend item is being clicked.

Private Sub winChartViewer1_ClickHotSpot(sender As Object, e As WinHotSpotEventArgs) _
    Handles winChartViewer1.ClickHotSpot

    If e("legend") <> "" Then
        MessageBox.Show("Clicked on " & e("legend"))
    End If

End Sub

Regards
Peter Kwan

  Re: Coordinates of Lengend Entry for a data set
Posted by Karen A on Nov-09-2020 13:44

<<From your earlier post, it seems you are using VB as the programming language. Are you using ChartDirector for .NET and is your program a desktop of web application?>>

I'm using Xojo with Monkeybread ChartDirector plugin. The app I'm working needs to be X-Platform (Mac and Windows)

I was able to implement clicking on individual data points on the chart in Xojo code  using the getXCoor(Xvalue) and  getYCoor(yValue) methods. I used those to build my own hit zones in Xojo to know if a point was clicked on.

<<Basically, the method is to use the image map for the LegendBox, obtained from LegendBox.getHTMLImageMap. This will turn the legend keys into "hot spots" that you can clicked on. This method also works for desktop applications.
>>

Ah... When i saw that method I did not think it would apply to a desktop app and so did not see a way to get the coordinates for the legends, but I figured there had to be a way!

<<Consider the "Simple Zooming and Scrolling" sample code>>

I'll check to see if Monkeybread included an example like that for Xojo code using ImageMaps  for desktop apps.

Thanks,
-Karen

  Re: Coordinates of Lengend Entry for a data set
Posted by Peter Kwan on Nov-09-2020 15:57
Hi Karen,

I am not familiar with Xojo myself, so I am not sure how it handles image maps. User interaction is highly framework specific. Even in our own releases, the image map handling in MFC/C++ and .NET/Windows Forms are quite different.

From online Xojo documentation, I found that they have ported the ImageMapHandler class, which is the method we use to handle image maps in C++/MFC:

https://www.monkeybreadsoftware.net/class-cdimagemaphandlermbs.shtml

Basically, you can use the image map (which is just a text string) to construct an ImageMapHandler. You can then use getHotSpot to determine if there is any hotspot at the specified coordinates. Usually, it is used in the some mouse event handler (such as the mouse move or mouse click handler) to determine if the mouse is over a hot spot. If it is over a hot spot, you can use getValue to get the hot spot parameter to identify the hot spot. In my previous post, I have set up the "legend" parameter in the image map to identify that it is over a legend item.

In some GUI frameworks, we have integrated some hot spot functions into the GUI control. If the Xojo control has not integrated image map support, you can use the ImageMapHandler and regular mouse events to perform the same functions.

Another method is to process the image map directly with your own code. The image map is standard HTML "<area>" tags. It is easy to process especially for legend items hot spots, which are always rectangular in shape.

Regards
Peter Kwan