Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question: Multiple DataZooms interconnected #317

Closed
HajiyevEl opened this issue Apr 14, 2024 · 1 comment
Closed

Question: Multiple DataZooms interconnected #317

HajiyevEl opened this issue Apr 14, 2024 · 1 comment

Comments

@HajiyevEl
Copy link

HajiyevEl commented Apr 14, 2024

Hi again!
Legend: I want to connect my charts so that when i zoom one of them, other charts also get zoomed.

Problem: I have multiple charts in GridLayout and added DataZoom components for each of them, because in your code in BaseChart.Component.cs, you are setting grid of 0 indexed axis as main grid for DataZoom:

        public GridCoord GetGridOfDataZoom(DataZoom dataZoom)
        {
            GridCoord grid = null;
            if (dataZoom.xAxisIndexs != null && dataZoom.xAxisIndexs.Count > 0)
            {
                var xAxis = GetChartComponent<XAxis>(dataZoom.xAxisIndexs[0]);
                grid = GetChartComponent<GridCoord>(xAxis.gridIndex);
            }
            else if (dataZoom.yAxisIndexs != null && dataZoom.yAxisIndexs.Count > 0)
            {
                var yAxis = GetChartComponent<YAxis>(dataZoom.yAxisIndexs[0]);
                grid = GetChartComponent<GridCoord>(yAxis.gridIndex);
            }
            if (grid == null) return GetChartComponent<GridCoord>();
            else return grid;
        }

So, to make multiple charts interconnected, i need to add DataZoom component for each of them and set each chart's xAxis index as 0 index in list of dataZoom.xAxisIndexs of that DataZoom component to make it main. (Or so i think)
Now, what i have:

DataZooms Screenshots

Screenshot 2024-04-14 121843
Screenshot 2024-04-14 121859
Screenshot 2024-04-14 121956

However, only first chart's DataZoom component work as intended. It could be zoomed in/out, and other charts also zoomed in/out together. But it's not possible from other charts, DataZoom component does not respond at all when dragging/scrolling etc. them. Is it intended behavior? How to make them interconnected properly so that all charts can be zoomed in/out from set indexes?

For now i removed additional DataZoom components except for single, and changed your code a little, but i don't want to change base code too much, because it will cause me problems when updating XCharts to newer versions.

        public GridCoord GetGridOfDataZoom(DataZoom dataZoom)
        {
            GridCoord grid = null;
            if (dataZoom.xAxisIndexs != null && dataZoom.xAxisIndexs.Count > 0)
            {
                //Edited code
                for (int i = 0; i < dataZoom.xAxisIndexs.Count; i++)
                {
                    var xAxis = GetChartComponent<XAxis>(dataZoom.xAxisIndexs[i]);
                    var tempGrid = GetChartComponent<GridCoord>(xAxis.gridIndex);
                    if (tempGrid.IsPointerEnter())
                    {
                        grid = tempGrid;
                        break;
                    }
                }

                //Old code
                //var xAxis = GetChartComponent<XAxis>(dataZoom.xAxisIndexs[0]);
                //grid = GetChartComponent<GridCoord>(xAxis.gridIndex);
            }
            else if (dataZoom.yAxisIndexs != null && dataZoom.yAxisIndexs.Count > 0)
            {
                //Edited code
                for (int i = 0; i < dataZoom.yAxisIndexs.Count; i++)
                {
                    var yAxis = GetChartComponent<YAxis>(dataZoom.yAxisIndexs[i]);
                    var tempGrid = GetChartComponent<GridCoord>(yAxis.gridIndex);
                    if (tempGrid.IsPointerEnter())
                    {
                        grid = tempGrid;
                        break;
                    }
                }

                //Old code
                //var yAxis = GetChartComponent<YAxis>(dataZoom.yAxisIndexs[0]);
                //grid = GetChartComponent<GridCoord>(yAxis.gridIndex);
            }
            if (grid == null) return GetChartComponent<GridCoord>();
            else return grid;
        }
@monitor1394
Copy link
Collaborator

I believe that your optimized code will work well, and if it's convenient for you, you should consider submitting it for a Pull Request (PR).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants