Controlling gaps for grid lines
Posted: Thu May 09, 2024 8:39 pm
I have a chart called TeeChart and I would like to add grid lines for both my left and bottom axes which both range from 0 -128. However I would like said gridlines to occur every 5 numbers shown for each axis and I would like for them to occur at every intersection for a grid line so that they sort of build a "+". So for example there should be a "+" (25, 25), (25, 50), (50, 25) etc. It is of my understanding that the following code that I have written should do that:
The issue I am having is that my gap which should be of length 25 relative to my axis, is not relative to its respective axis. Same thing with the length of the dash, but this is less of a concern than the gap is. Is there a way to force the gap length to be relative to the size of my axis? Please let me know if you would like me to provide anything else for the chart to better assist me. I have also tried to use the DashPattern property instead, but it seems to have the same issue.
Code: Select all
// Ensure regular gridlines are visible
TeeChart.Axes.Bottom.Grid.Visible = true;
TeeChart.Axes.Left.Grid.Visible = true;
//Adding grid line every 5 numbers shown on axis
TeeChart.Axes.Bottom.Grid.DrawEvery = 5;
TeeChart.Axes.Left.Grid.DrawEvery = 5;
// Define dash style for the X-axis (Bottom axis)
System.Windows.Media.DoubleCollection dashArrayX = new System.Windows.Media.DoubleCollection();
dashArrayX.Add(5); // Length of dash at y-coordinate 0
dashArrayX.Add(25); // Length of gap between y-coordinate 0 and 25
// Set the dash style for the bottom axis (X-axis)
TeeChart.Axes.Bottom.Grid.Style = new System.Windows.Media.DashStyle(dashArrayX, 0);
// Define dash style for the Y-axis (Left axis)
System.Windows.Media.DoubleCollection dashArrayY = new System.Windows.Media.DoubleCollection();
dashArrayY.Add(5); // Length of dash
dashArrayY.Add(25); // Length of gap
// Set the dash style for the left axis (Y-axis)
TeeChart.Axes.Left.Grid.Style = new System.Windows.Media.DashStyle(dashArrayY, 0);