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. Image for the cookie policy date
close icon

New Series object necessary on DataTable structure change?

When using a data-bound chartseries, if you ever change the structure of the datatable, the chartseries is no longer bound.

For instance, if I create a chartseries that binds to a particular column on a datatable, when I have not yet populated the columns of the datatable, after I populate the columns and rows the series does not update with that data.

I have tested a bunch of different things (see code below), but it seems like the only way to solve this problem is to create a whole new series.

This seems like there should be a nice way to rebind a series, so that I don't have to recreate the whole series from scratch, including all series formatting... Please let me know. thanks.



Imports Syncfusion.Drawing
Imports Syncfusion.Windows.Forms.Chart
Public Class Form1

Dim dt As System.Data.DataTable

Private Sub btnBind_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBind.Click
Dim s As ChartSeries = NewDataBoundSeries(Me.ChartControl1, dt, "Value", "Y", "X", New BrushInfo(Color.Coral), ChartSeriesType.Line)
Me.ChartControl1.Series.Add(s)



End Sub

Private Sub btnPopulate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPopulate.Click
dt = New DataTable
dt.Columns.Add("X", GetType(Date))
dt.Columns.Add("Y", GetType(Double))


For i As Integer = 1 To 12
dt.Rows.Add(dt.NewRow())
dt.Rows(dt.Rows.Count - 1).Item("X") = New Date(2008, i, 1)
dt.Rows(dt.Rows.Count - 1).Item("Y") = 100 * Rnd()

Next

If Me.ChartControl1.Series(0).Name = "Value" Then
Dim c As New ChartDataBindModel(dt, dt.TableName)

With CType(Me.ChartControl1.Series(0).SeriesModel, ChartDataBindModel)
.DataSource = dt
.DataMember = dt.TableName
.DataBind()


c.XName = .XName
c.YNames = .YNames
End With


Me.ChartControl1.Series(0).SeriesModel = c
End If
End Sub

Private Sub btnRebuildRecordset_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRebuildRecordset.Click
For i As Integer = 1 To 12
dt.Rows.Add(dt.NewRow())
dt.Rows(dt.Rows.Count - 1).Item("X") = New Date(2008, i, 1)
dt.Rows(dt.Rows.Count - 1).Item("Y") = 100 * Rnd()

Next
End Sub


Private Function NewDataBoundSeries(ByVal c As ChartControl, ByVal dt As DataTable, _
ByVal SeriesName As String, ByVal SeriesFieldName As String, _
ByVal SeriesXAxisName As String, ByVal BrushInfo As BrushInfo, ByVal LineType As ChartSeriesType) As ChartSeries

Dim series As ChartSeries = c.Model.NewSeries(SeriesName, LineType)
Dim model As New ChartDataBindModel(dt, dt.TableName)
model.XName = SeriesXAxisName
model.YNames = New String() {SeriesFieldName}

series.SeriesModel = model
series.Style.Interior = BrushInfo

Return series
End Function



Private Sub btnClearAll_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClearAll.Click
dt.Clear()
End Sub

Private Sub btnClearRows_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClearRows.Click
dt.Rows.Clear()
End Sub

Private Sub ChartControl1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ChartControl1.Click

End Sub

Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Me.ChartControl1.PrimaryXAxis.DateTimeRange = New ChartDateTimeRange(New Date(2008, 1, 1), New Date(2008, 12, 1), 1, ChartDateTimeIntervalType.Months)

End Sub
End Class



10 Replies

MA Manohari Syncfusion Team September 14, 2008 07:38 PM UTC

Hi Robert,

It is possible to update the Chart when Database is updated by using the DatabindModel.RaiseListChanged method.

Example:

private void buttonUpdateData_Click(object sender, EventArgs e)
{
DateTime dt1 = new DateTime(2008, 9, 14, 0, 0, 0);
int i = dt.Rows.Count;
for (int j = i-1; j < i+5;j++)
{
dt.Rows.Add(dt.NewRow());
dt.Rows[dt.Rows.Count - 1]["X"] = dt1.AddMonths(j + 1);
dt.Rows[dt.Rows.Count - 1]["Y"] = 100 * rnd.Next(1, 10);
}

this.model.RaiseChangedEvent(new System.ComponentModel.ListChangedEventArgs(System.ComponentModel.ListChangedType.Reset, 0));
}

I have attached the sample that illustrates the same in this link below.

http://websamples.syncfusion.com/samples/Chart.Windows/F76465/Sample1.htm

Kindly let us know if this meets your requirement. Thanks for your patience.

Regards,
Manohari.R




RA Robert Avery September 19, 2008 12:19 AM UTC

I am using VS2008 with Syncfusion 3.6.0.6.

Unable to read the project file 'DatafromDataBase_2005.csproj'.

C:\Documents and Settings\avery\Desktop\SyncFusion Examples\DataTable Structure requiring new series\DatafromDataBase_2005.csproj(101,5): The project file could not be loaded. The 'Reference' start tag on line 68 does not match the end tag of 'ItemGroup'. Line 101, position 5.



MA Manohari Syncfusion Team September 19, 2008 06:06 AM UTC

Hi Robert,

We regret very much for the inconvenience caused. Please find the corrected sample in the following link.

http://websamples.syncfusion.com/samples/Chart.Windows/F76465/Sample1.htm

Kindly let us know if you have any other queries. Thanks for your patience.

Regards,
Manohari.R



RA Robert Avery September 19, 2008 07:54 PM UTC

I agree that your sample works, but it does not address the key problem I have. My problem is that it breaks when you "change the structure of the datatable". For instance, if you bind the series to a table, then remove all columns in the table, then add all the columns back (such that you are changing not just the data, but more importantly the structure), the series binding no longer works, as in the sample code I posted originally.

Let me know what will solve this problem. Thanks.



RA Robert Avery October 10, 2008 07:45 PM UTC

How can I provide additional clarification on this issue to figure this out?



MA Manohari Syncfusion Team November 1, 2008 05:47 PM UTC

Hi Robert,

We regret for the delayed response. I have tested for this issue and was able to reproduce this behvaior [ChartSeries is not updated when table structure has been Changed]. I have forwarded this to our Development team and will get back to you with more information regarding this within three business days.

Kindly let us know if you need any other information. Thanks for your patience.

Regards,
Manohari.R



MA Manohari Syncfusion Team November 21, 2008 01:43 PM UTC

Hi Robert,

We regret vrey much for the delayed response. This behavior is suspected to be defect and I have created a defect report [#12460] in this regard and have forwarded it to our Development team. We will get back to you regarding the timeline for fixing this issue within two business days.

You can track the progress of this bug fix in this link below.

Defect #12460 - Databinding fails when the databound table structure is changed.

Please let me know if you need any other information. Thanks for your patience.

Regards,
Manohari.R



MA Manohari Syncfusion Team November 26, 2008 06:35 AM UTC

Hi Robert,

Thanks for your patience. I have consulted with our team regarding the fix time line for this issue [Defect #12460]. Fix for this issue will be available on December 19th 2008 and we will get back to you on the specified date with more details in this regard.

Please let me know if you need any other information.

Regards,
Manohari.R




RA Robert Avery December 22, 2008 03:54 PM UTC

Has this fix been released?



MA Manohari Syncfusion Team December 23, 2008 07:10 PM UTC

Hi Robert,

We regret for the delay in getting back to you. We are glad to let you know that the issue [Databinding fails when the databound table structure is changed.] been fixed. The fix for this defect is available in our Latest Development build v7.1.0.8.

The latest Development build version 7.1.0.8 can be downloaded from the following link.

http://www.syncfusion.com/downloads/product/build.aspx

If your Essential Studio license is current, you will be able to obtain the key to install this version from your account in DirectTrac. Otherwise, please contact your Syncfusion Sales Representative or e-mail salessupport@syncfusion.com. Please let us know if you have any problem with this version.

I have also attached a sample that updates the chart correctly when the DataTable bound to the ChartSeries is recreated in this link below for your reference.

http://websamples.syncfusion.com/samples/Chart.Windows/F76465/Sample2.htm

Please let us know if this resolves your problem. Thanks for your patience.

Regards,
Manohari.R


Loader.
Live Chat Icon For mobile
Up arrow icon