none
Scrolling/Moving MS chart area to highlighted datapoint when in zoom state RRS feed

  • Question

  • Hi,

    I am displaying data in MS Chart from Datagridview.

    When selecting an row in the datagridview, I am highlighting the datapoint in the chart with different color.

    When chart is in zoom state , When highlighting the datapoint and if it is not in visible state, I have to scroll/move the chart to highlighted datapoint.

    How to achieve this?

    Thursday, June 13, 2019 12:52 PM

All replies

  • Hi sgrm123,

    Maybe you can try the following code to highlight the specific point with different color, and redirect the location.

        private void Form1_Load(object sender, EventArgs e)
        {
            // ...
            // Code omitted
            // ...
            dataGridView1.RowEnter += dataGridView1_RowEnter;
        }
    
        private void dataGridView1_RowEnter(object sender, DataGridViewCellEventArgs e)
        {
            // highlight the point
            chart1.Series[0].Points[e.RowIndex].Color = Color.Red;
            // redirect the location     
            chart1.ChartAreas["ChartArea1"].AxisX.ScaleView.Position = index;
        }
    
        private void dataGridView1_RowLeave(object sender, DataGridViewCellEventArgs e)
        {
            // Restore the original color
            chart1.Series[0].Points[e.RowIndex].Color = Color.Blue;
        }

    Regards,

    Kyle


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, June 14, 2019 5:27 AM
    Moderator
  • Hi sgrm123,

    Maybe you can try the following code to highlight the specific point with different color, and redirect the location.

        private void Form1_Load(object sender, EventArgs e)
        {
            // ...
            // Code omitted
            // ...
            dataGridView1.RowEnter += dataGridView1_RowEnter;
        }
    
        private void dataGridView1_RowEnter(object sender, DataGridViewCellEventArgs e)
        {
            // highlight the point
            chart1.Series[0].Points[e.RowIndex].Color = Color.Red;
            // redirect the location     
            chart1.ChartAreas["ChartArea1"].AxisX.ScaleView.Position = index;
        }
    
        private void dataGridView1_RowLeave(object sender, DataGridViewCellEventArgs e)
        {
            // Restore the original color
            chart1.Series[0].Points[e.RowIndex].Color = Color.Blue;
        }

    Regards,

    Kyle


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

     chart1.ChartAreas["ChartArea1"].AxisX.ScaleView.Position = index;
    How to calculate index value?
    Friday, June 14, 2019 7:37 AM
  • Hi sgrm123,

    Sorry for my mistake, just modify it to "e.RowIndex".

    Regards,

    Kyle


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, June 14, 2019 8:10 AM
    Moderator
  • Hi sgrm123,

    Sorry for my mistake, just modify it to "e.RowIndex".

    Regards,

    Kyle


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    It did not work.
    Friday, June 14, 2019 8:13 AM
  • Hi,

    Could you provide you code? A simple full demo will be better. It works fine on my machine.

    Regards,

    Kyle


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, June 14, 2019 8:24 AM
    Moderator
  • Hi,

    Could you provide you code? A simple full demo will be better. It works fine on my machine.

    Regards,

    Kyle


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Could you please share your code?

    Whether your chart is in zoom state?

    My chart is not having scrollbar.

    My X values are datetime.



    • Edited by sgrm123 Friday, June 14, 2019 9:08 AM
    Friday, June 14, 2019 8:27 AM
  • Hi,

    I am sorry that I misunderstand your need before. To handle the issue more efficiently, could you provide your current code demo?

    Regards,

    Kyle


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, June 18, 2019 9:40 AM
    Moderator