programmatically create grid of WpfPlot controls #3
See original GitHub issueHi Scott, I have a class that creates a 12 x 8 grid which is partly shown below. The code in the class fills each cell with a ScottPlot.WpfPlot object as shown below. The WPF XAML code displays these plots nicely on a WPF grid, but… weirdy thing is that this code produces a rectangular plot outline box at (0,0) which is top left position even if I never call the setRow and setColumn, but just use the first code block below. If I click inside the rectangle, gridlines appear and axes are both labeled from -1 to +1. I’m wondering if there is a small bug that places a minimum of one rectangle on the grid? Other locations on the grid, where I add data using the second block of code below, plot the data nicely at the correct locations. Any thoughts?
First code block
public ScottPlotGrid(Grid SPGrid, int numPlotColumns, int numPlotRows)
{
this.SPGrid = SPGrid;
this.numPlotColumns = numPlotColumns;
this.numPlotRows = numPlotRows;
this.SPGrid.ColumnDefinitions.Clear();
for (int i = 0; i < numPlotColumns; i++)
this.SPGrid.ColumnDefinitions.Add(new ColumnDefinition());
this.SPGrid.RowDefinitions.Clear();
for (int i = 0; i < numPlotRows; i++)
this.SPGrid.RowDefinitions.Add(new RowDefinition());
wpfPlot = new ScottPlot.WpfPlot[numPlotColumns * numPlotRows]; // Create and array to hold the row x col ScottPlot objects
for (int idx = 0; idx < (numPlotColumns * numPlotRows); idx++) // Instantiate ScottPlot objects, and pop them into the grid
{
wpfPlot[idx] = new ScottPlot.WpfPlot();
SPGrid.Children.Add(wpfPlot[idx]);
}
}
Second code block
public void PlotCorrelation(int wellNum, int numCols, AviDataStor dataStor)
{
wpfPlot[wellNum].plt.PlotScatter(dataStor.dataColumns[0], dataStor.dataColumns[1], lineWidth: 0, markerSize: 3);
wpfPlot[wellNum].plt.AxisAuto();
wpfPlot[wellNum].Render();
Grid.SetColumn(wpfPlot[wellNum], wellNum % numCols); // Convert linear well number into 2d row/column
Grid.SetRow(wpfPlot[wellNum], wellNum / numCols);
}
Issue Analytics
- State:
- Created 4 years ago
- Comments:8 (6 by maintainers)
Top GitHub Comments
Then you do
SPGrid.Children.Add(wpfPlot[idx]);
and not specifyGrid.Row
,Grid.Column
for them, they all dropped to (0, 0) element of Grid.To follow WPF patterns you must avoid using code behind instead of xaml for markup. For that you can do: Make simple container for Grid element:
Make property in window class (code behind) to hold that elements:
Fill that list in window constructor:
and bind that list using xaml:
controlGrid
is the window name, you can specify it in<window>
sectionThis may be a better answer:
This code block is placing an empty ScottPlot into every grid square. If you don’t want a grid placed at (0, 0), modify the for loop to start at 1:
int idx = 1
EDIT: this post relates to #257 and #267