We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy.
Unfortunately, activation email could not send to your email. Please try again.

Connection between the chart data and a grid.

Thread ID:

Created:

Updated:

Platform:

Replies:

44008 May 10,2006 01:51 PM May 16,2006 04:59 AM Windows Forms 3
loading
Tags: GridControl
Amit Weisman
Asked On May 10, 2006 01:51 PM

Hi. I have data which is not from data base, just internal in-memory structure. Currently I present this data in a chart (after moving it into series of points). I would like to add a table of the chart which will include a row (or a column) for each series of points. So I’ll have a visual representation of the data in the chart and a textual one in the table. Is there a built-in option like the one I just described? Is the virtual grid is the grid option that best suites my needs(any grid like control will do, I don’t need the full strength of the grid, just basic , column sorting , choosing a range etc.)? Is there an easy way to connect the chart data to the virtual grid? I hope my point is clear. I’d appreciate any input on the subject. Because I’m trying to incorporate two packages I post the same message on both the Grid forum and the Chart forum. Thanks Amit

Administrator [Syncfusion]
Replied On May 11, 2006 03:43 AM

Hi Amit, Connection between Chart data and GridControl : There is no build-in support for connecting the chart data and grid control.You need to write your own logic to make the connection between Chart data and Grid control.Please refer to the attached sample for more details. Here is a sample. http://www.syncfusion.com/Support/user/uploads/VirtualGridChart_92c31a4e.zip Sorting in Virtual Grid: In a virtual grid, there is no built-in support for sorting. The reason for this is in a virtual Grid, the data is maintained seperately and is provided on demand to the grid using the QueryCellInfo event handler. So whatever the data comes in through this event handler, the grid just displays it. It has no control over the external datasource. So there are two ways to display sorted data in the virtual grid: 1) The simplest way is to sort the underlying datasource. If your datasource is something that supports sorting (like a DataView or some other IBindingList objects that supports sorting), then you can apply the sorting on your datasource. It will physically rearrange the external datasource so that the sorted data is displayed with no changes to the QueryCellInfo. 2) The second option would be to create some sort of index array during your sort where the array tracks in some manner the relationship between the unsorted data and the sorted data. Then in your QueryCellInfo handler, you would use this array to get the proper reference for the requested row. Attached is a sample in C# that shows an implementation of the second option. Here are some details about the sample. It uses a two dimensional integer array called VirtData as the datasource for the grid. The datasource has an ArrayList (SortIndexList) with the capacity as the number of rows. It is initially populated with 0,1,2,3.. till the total rowcount. The virtdata class has an indexer that gets and sets the array values using the SortIndexList items. The grid is populated using the QueryCellInfo event handler using this indexer. Since the SortIndexList is populated like 0,1,2,3.. intially, it displays the array values using this indexer. It uses the "ColumnHeaderCell" to display the up or down sort arrows when the column header cell is clicked to show the sort order. When the header cell is clicked, the SortIndexList''s sort method is called passing in the DataComparer which implements the IComparer interface. The IComparer re-arranges items (which we loaded intially like 0,1,2,3...) in a way to reflect either the ascending or descending way of array data in that particular column. So when the grid queries for information using the virtdata indexer, it gets the value in a sorted way and displays in the grid. Here is a sample. http://www.syncfusion.com/support/user/uploads/virtgridsort632182571762678096.zip Please let me know if this helps. Best Regards, Haneef

Amit Weisman
Replied On May 15, 2006 09:38 AM

Hi Haneef . Thanks for your reply. I guess by now you already understand what I want to do (according to your first example). I have data that I would like to put into a chart and a grid at the same time and have some sorting capabilities on the grid. Option 1 : Use the virtual grid and implement a layer that will connect the query in the grid with the data in the chart series. This is nice and quick but then I’ll have to do heavy lifting to get the sorting feature (sort each time according to another X point in the chart). Options 2 : Use a simple grid. I still don’t know how to get the sorting to work (I hope sorting along a column is simple) , but I have to manually put each point in the table because I can’t “load” a series of points to the grid at once. This looks like a waste of time (let’s say I can live with the memory for hold two copies of the data). I’m looking for something like this (see attached project) : double [] x = new double[] {10 , 20 , 30 , 40 , 50} ; double [] y = new double[] {23 , 43 , 78 , 49 , 21} ; // insert the data to the chart ChartSeries cs = this.chartControl1.Model.NewSeries() ; for(int i = 0 ; i < y.Length ; i++) cs.Points.Add(x[i] , y[i]) ; this.chartControl1.Series.Add(cs) ; // insert the data to the table this.gridControl1.Model.PopulateValues( GridRangeInfo.Cells(1 , 1 , 1 , 5) , cs.SeriesModel) ; What can I “put” instead of cs.SeriesModel at the last line to make this work ? Any other options ? Ideas ? Is there a way to get an array from the series that can be loaded into the grid ? (I post this in both the chart and grid forums) Thanks Amit

WindowsApplication440.zip

Administrator [Syncfusion]
Replied On May 16, 2006 04:59 AM

Hi Amit, I have created a sample as per your specification.The sample illustrates the possiblity to sort the virtual grid when the current record is changed. Please refer to the attached sample and let us know if you are trying something different. Sample Description: // pass the chartcontrol data to the grid. this.gridControl1.theData = new VirtData(this.chartControl1); this.gridControl1.ResetVolatileData(); //For virtual grid purpose. //sort the grid(after moving to the next record) ,when the record is changed. private void gridControl1_CurrentCellMoved(object sender, Syncfusion.Windows.Forms.Grid.GridCurrentCellMovedEventArgs e) { GridCurrentCell cc = this.gridControl1.CurrentCell; if(cc.MoveFromRowIndex != cc.MoveToRowIndex && isChanged) { //this.gridControl1.theData.SortVirtData(0,ListSortDirection.Descending); //For descending (any particular) order. this.gridControl1.SortCol(1); // 1 for first column (sorting based on first column) this.gridControl1.Refresh(); isChanged = false; } } } //for detecting the record changes. bool isChanged = false; private void gridControl1_CurrentCellChanged(object sender, System.EventArgs e) { isChanged = true; } Here is a modified sample. http://www.syncfusion.com/Support/user/uploads/DoubleVirtualGridChart_40780787.zip Thanks for your interest in Syncfusion products. Best Regards, Haneef

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;