|
Query |
Response |
|
I would like to link a selected range of cells to a selected, embedded chartcontrol to be its data source, much like Excel charts, so that when data changes in the gridcontrol range it would automatically update the chartcontrol. I have seen a couple of forum entries asking about this idea, but they were quite old and did not have a solution at the time. At this point, is there a good method to link gridcontrol range data to a chartcontrol? |
GridControl does have the support to render the chart control based on the Gridcell value. Please refer the following dashboard sample.
|
|
embedding chartcontrols into cells and then merging cells to edit the size of the charts works, but is there a good and simple way to be able to drag the charts to move them as well as resize them? |
To load the chart control for grid cells, you could use the Control cell type and use the Control property. Please refer the following code example
C#
ChartControl chart = new ChartControl();
hart.Dock = DockStyle.Fill;
this.gridControl1[2, 3].CellType = GridCellTypeName.Control;
this.gridControl1[2, 3].Control = chart;
Once you have loaded the chart control inside of the cell, you could not resize the chart directly but you can resize the cell to increase the chart height/width. |
|
Query |
Response |
|
is there a way to include the row and column headers in the cell range so that the c axis labels reflect the row headers and the series names reflect the column headers? |
If you want to use the header title for chart, you could use the 0th index to get the value.
Example
To get the column header,
string colHeader = this.Grid[0, this.cellvalueGridRangeInfo.Left].Text;
To get the row header value,
string rowHeader =this.Grid[this.cellvalueGridRangeInfo.Top, 0].Text; |
|
In addition to the charts, I like the idea of using gridcontrol as a workbook.
Is it possible to reference ranges from another sheet in a formula (I.e. reference range in sheet 1 in a formula in sheet2).
And is it possible to define named ranges for use in formulas (give a name to a column of data)
|
To refer the GridControl cell reference in another GridControl like as workbook, you could register that grid using GridFromulaEngine.RegisterGridAsSheet method and use the FormulaCell celltype for grid cells. Please refer the following code example and dashboard sample,
C#
GridFormulaEngine.RegisterGridAsSheet("gridControl1",this.gridControl1.Model, 0);
this.gridControl1.TableStyle.CellType =GridCellTypeName.FormulaCell;
|
|
1) is it possible to save embedded charts along with saving the workbook? |
The GridControl does not has the support to export the cells with CellType as Control. However, your requirement can be achieved by converting the chart into image in a temp cell with CellType as Image. Please refer to the below UG to convert the chart into image,
Note
The imported chart as image can not be edited in the workbook.
|
|
2) is it possible to export the workbook to pdf including the embedded charts ? |
By default, the page content will be converted as image to export as pdf. So, the exported chart image can be exported to pdf by using the ExcelToPdfConverter. We already documented a knowledge base to convert the excel to pdf and please refer to the below KB link for further details,
|
|
3) serializing a chart control does not serialize all chart properties. I have asked about this before but it has been a long time. Are there plans to allow serializing all available properties, such as custom xaccess labels and symbol (marker) properties? |
We have forwarded you query to corresponding development team to validate further on this requirement. So, we will update the details on 10th June 2019. |
ChartControl myChartControl = new ChartControl();
this.workBook._grid[this.workBook._grid.CurrentCell.RowIndex, this.workBook._grid.CurrentCell.ColIndex].CellType = "Control"; this.workBook._grid[this.workBook._grid.CurrentCell.RowIndex, this.workBook._grid.CurrentCell.ColIndex].Control = myChartControl; this.workBook._grid.Controls.Add(myChartControl);
myChartControl.Font = new Font("Calibri", 8F, FontStyle.Regular, GraphicsUnit.Point);
this.workBook._grid.CoveredRanges.Add(GridRangeInfo.Cells(this.workBook._grid.CurrentCell.RowIndex, this.workBook._grid.CurrentCell.ColIndex, this.workBook._grid.CurrentCell.RowIndex + 5, this.workBook._grid.CurrentCell.ColIndex + 5));
2) Hosting chartcontrol as child of grid:
ChartControl myChartControl = new ChartControl();
myChartControl.Parent = this.workBook._grid;
myChartControl.BringToFront();
* This is the preferred experience because I can then add logic to allow dragging and resizing with the mouse, but gets messed up when scrolling the grid.
The 2 PDF conversion methods I have tried are:
1) Simply exporting the GridControl using the gridconverter when the charts are embedded:
string exeDir = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
GridPDFConverter pdfConverter = new GridPDFConverter();
PdfDocument Pdoc = new PdfDocument();
Pdoc.PageSettings.Orientation = PdfPageOrientation.Landscape;
string pdf = exeDir + "\\" + toolStripComboBox1.Text + ".pdf";
pdfConverter.ExportToPdf(Pdoc, this.workBook._grid, GridRangeInfo.Cells(1, 1, 39, 16));
Pdoc.Save(pdf);
*This produces the grid with the charts as images and they are very low quality.
2) Drawing the grid and charts to Graphics and then "printing" to pdf document. This works great when chartcontrols are simply children of the grid:
System.Drawing.Printing.PrintDocument pd = new System.Drawing.Printing.PrintDocument();
pd.PrintPage += new PrintPageEventHandler(pd_PrintPage)
pd.PrinterSettings.DefaultPageSettings.Margins.Left = 25;
pd.PrinterSettings.DefaultPageSettings.PrinterResolution.Kind = PrinterResolutionKind.High;
pd.PrinterSettings.PrinterName = "Microsoft Print to PDF";
pd.PrinterSettings.PrintToFile = true;
string exeDir = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
pd.PrinterSettings.PrintFileName = Path.Combine(exeDir + \\Test.pdf);
pd.Print();
private void pd_PrintPage(object sender, PrintPageEventArgs ev)
{
GraphicsState transState = ev.Graphics.Save();
//Drawing Grid
System.Drawing.Rectangle myRec = new System.Drawing.Rectangle(this.workBook._grid.Location.X, this.workBook._grid.Location.Y, this.workBook._grid.Width, this.workBook._grid.RowCount * this.workBook._grid.DefaultRowHeight);
this.workBook._grid.DrawGrid(ev.Graphics, myRec, true);
//Drawing each chart (chartListGrid1 is a separate grid that keeps a list of all charts added to the grid)
for (int i = 1; i <= chartListGrid1.RowCount; i++)
{
Control[] controlsD = this.Controls.Find(chartListGrid1[i, 1].Text, true);
ChartControl chart = controlsD[0] as ChartControl;
System.Drawing.Rectangle myRec2 = new System.Drawing.Rectangle(chart.Location.X, chart.Location.Y, chart.Width, chart.Height);
chart.Draw(ev.Graphics, myRec2);
ev.Graphics.Restore(transState);
ev.Graphics.ResetTransform();
ev.Graphics.ResetClip();
}
}
*This method renders the chartcontrols beautifully and would be great for children charts if the scroll issue could be solved.
Interesting, using this method when charts are embedded in cells does improve the image quality some but still not to an exceptable level.
I thought about using this method with the embedded charts in cells by drawing the chartcontrols on top of the chart images but I realized the actual chartcontrols do not match the size and location of the embedded chart images when in a merged cell range. If it is possible to detect the size and location of the chart images and then apply those sizes and location to each chart then that may be possible. Is it possible to detect the size and location of the Merged Cell Range that each chart is in?
Any ideas on how to solve the image quality or scrolling issue will be greatly appreciated! Thanks for your help, you guys are awesome!
What I was hoping for is the ability to draw the grid as well as each chartcontrol to graphics (by looping through them and using their built-in drawing features) like I am doing in my Pd_PrintPage event but instead of drawing those controls directly to a PrintDocument I would like to be able to draw them directly to a Syncfusion PdfDocument if possible. Drawing them directly to graphics allows for the highest possible resolution because it does not skew any proportions like an image tends to do.
Thanks.