in

C1 Community

ComponentOne Community is a free source for developers and help authors to collaborate and communicate.

CoordToPointIndex

Last post 06-30-2008 9:23 AM by alanis. 5 replies.
Page 1 of 1 (6 items)
Sort Posts: Previous Next
  • 06-27-2008 6:38 AM

    • alanis
    • Top 500 Contributor
    • Joined on 07-31-2006
    • Posts 9

    CoordToPointIndex

    To improve user experience I would like my user to able to click in the chart and get details about the position they click (information about all channels, average, spreads etc.).

     A server-side solution would be (but not working) :

       protected void C1WebChart1_Click(object sender, ImageClickEventArgs e)
        {
            Axis ax = C1WebChart1.ChartArea.AxisX;
            int SeriesOutput = 0;
            int PointOutput = 0;
            int DistanceOutput = 0;
            if (C1WebChart1.ChartGroups.Group0.CoordToPointIndex(e.X, e.Y, PlotElementEnum.Points, 1, ref PointOutput, ref DistanceOutput))
            {
                ax.Text = e.X + ", " + e.Y + " -> " + PointOutput;
            }
            else
            {
                ax.Text = "Conversion failed";
            }
        }

     

    This example does not return any 'good' points. When clicking in the chart it always return the maximum number of points for PointOutput. Outside the chart most of the clickpoints return 0.

     Am I doing something wrong in this code?

     

    Another approach is using the general callback. Strangely enough with the same input I get different output for the CoordToPointIndex function. The pointoutput becomes -1. Can someone explain this?


    Thanks for helping

    Ralph

     

    Filed under:
  • 06-27-2008 9:05 AM In reply to

    • alanis
    • Top 500 Contributor
    • Joined on 07-31-2006
    • Posts 9

    Re: CoordToPointIndex

     I found out that it has something to do with the size definition.

    This one works for OnClick:

    <C1WebChart:C1WebChart ID="C1WebChart1" runat="server" Width="543px" Height="431px" ongeneralcallback="C1WebChart1_GeneralCallback" ImageFormat="Png" SlidingExpiration="00:00:30" ImageQuality="100" OnClick="C1WebChart1_OnClick">

     

    This one doesn't work :

    <C1WebChart:C1WebChart ID="C1WebChart1" runat="server" Width="60%" Height="80%" ongeneralcallback="C1WebChart1_GeneralCallback" ImageFormat="Png" SlidingExpiration="00:00:30" ImageQuality="100" OnClick="C1WebChart1_OnClick">

     

    Does anyone have an explanation for this?

     

    The version using GeneralCallback still isn't working even though I checked the input values. They are exactly the same, but only a result for the OnClick version????

    Filed under:
  • 06-27-2008 9:17 AM In reply to

    • C1_GregL
    • Top 10 Contributor
    • Joined on 06-11-2007
    • Pittsburgh PA
    • Posts 500

    Re: CoordToPointIndex

    In your code, PointOutput should return the point index within its series.  If you have multiple series you should use CoordToSeriesIndex to first return the series, and then CoordToPointIndex to return the point within that series.  Once you have the SeriesIndex you can get data statistics such as:

    c1WebChart1.ChartGroups.Group0.ChartData.SeriesList[SeriesOutput].PointData.Statistics.Mean.ToString()

    With the data point index you can get the point values from:

    c1WebChart1.ChartGroups.Group0.ChartData.SeriesList[SeriesOutput].PointData[PointOutput].ToString()

    If this does not work for you, please provide a sample and C1WebChart version number as there may be something else causing the problem. 

    hope that helps,
    Greg L

  • 06-27-2008 9:39 AM In reply to

    • alanis
    • Top 500 Contributor
    • Joined on 07-31-2006
    • Posts 9

    Re: CoordToPointIndex

     It got the OnClick version working (although I don't understand why)

    However I would like to know why there is a difference between the OnClick and generalcallback way. When using the same handling code :

            if (C1WebChart1.ChartGroups[0].CoordToPointIndex(x, y, PlotElementEnum.Points, 0, ref PointOutput, ref DistanceOutput))
            {
                ax.Text = e.X.ToString() + " -> " + PointOutput.ToString();
                ZoomIn(PointOutput);
            }

    I checked the inputs x and y and they are the same. Is the state of the chart not the same when using the OnClick or the generalcallback??

     

    Thanks again!

    Ralph

  • 06-30-2008 8:45 AM In reply to

    • C1_GregL
    • Top 10 Contributor
    • Joined on 06-11-2007
    • Pittsburgh PA
    • Posts 500

    Re: CoordToPointIndex

    Hi Ralph,

    The difference is that GetImage() is built into the Onclick event and not in GenerateCallback.  To use CoordToPoint it is necessary for C1WebChart to render itself internally and this does not usually happen until after the callback is completed.  Getimage is not built-into GenerateCallback due to it not being desirable for all scenarios.  Most of the time, you would not want to render the chart in callback, because it can slow things down if you don't need it, but in your case it's necessary.

    The simplest way to force the chart to render is GetHtmlMap.  So you would call this in your GenerateCallback event before CoordToPointIndex.

    c1WebChart1.ImageAreas.GetHtmlMap();

    Hope that helps,
    Greg L

     

  • 06-30-2008 9:23 AM In reply to

    • alanis
    • Top 500 Contributor
    • Joined on 07-31-2006
    • Posts 9

    Re: CoordToPointIndex

     Hi Greg,

     Great! That works like a charm!

     

    Ralph

Page 1 of 1 (6 items)
Contact ComponentOne: 1.800.858.2739 ©1987-2008 ComponentOne LLC All Rights Reserved.