Binding a Chart to a Datatable

TeeChart for Microsoft Visual Studio .NET, Xamarin Studio (Android, iOS & Forms) & Monodevelop.
Post Reply
Mike Jones
Advanced
Posts: 192
Joined: Thu Feb 01, 2007 12:00 am
Contact:

Binding a Chart to a Datatable

Post by Mike Jones » Wed Aug 13, 2008 10:14 pm

When I bind a tchart to a datatable like what is in the TChart for .NET
Example application at "Welcome !\Datasets\Data table XY Series"

I see that if I go to the Chart Editor and go to the Data tab that no data points are shown.

1. Can I not see the data in the Data tab of the chart editor? or is this a bug?
2. If I add a DragMarks tool and assign it to my series and have it only edit the Y values. When I change a points Y value by dragging, does it update the underlying DataTable? If not how can I make it do this?

Christopher
Site Admin
Site Admin
Posts: 1349
Joined: Thu Jan 01, 1970 12:00 am
Location: Riudellots de la Selva, Catalonia
Contact:

Re: Binding a Chart to a Datatable

Post by Christopher » Thu Aug 14, 2008 9:44 am

Hello,
Mike Jones wrote:When I bind a tchart to a datatable like what is in the TChart for .NET
Example application at "Welcome !\Datasets\Data table XY Series"

I see that if I go to the Chart Editor and go to the Data tab that no data points are shown.
Mmmm, the following code seems to work ok here using the latest release:

Code: Select all

    public Form3()
    {
      InitializeComponent();
      InitializeChart();
    }

    private Steema.TeeChart.Styles.Line series;
    Steema.TeeChart.TChart tChart1; 

    private void InitializeChart()
    {
      tChart1 = new Steema.TeeChart.TChart();
      tChart1.Dock = DockStyle.Fill;
      this.Controls.Add(tChart1);

      series = new Line(tChart1.Chart);
      series.DataSource = GetData();
      series.XValues.DataMember = "X";
      series.YValues.DataMember = "Y";

      tChart1.DoubleClick+=new EventHandler(tChart1_DoubleClick);
    }

    private DataSet GetData()
    {
      DataSet TeeDataSet = new DataSet();
      DataTable TeeDataTable = new DataTable();

      DataRow newRow;

      DataColumn xval = new DataColumn("X", typeof(double));
      DataColumn yval = new DataColumn("Y", typeof(double));

      TeeDataTable.Columns.Add(xval);
      TeeDataTable.Columns.Add(yval);

      for (int i = 0; i < 10; i++)
      {
        newRow = TeeDataTable.NewRow();
        newRow[xval] = i;
        newRow[yval] = i;
        TeeDataTable.Rows.Add(newRow);
      }

      TeeDataSet.Tables.Add(TeeDataTable);
      return TeeDataSet;

    }

    void tChart1_DoubleClick(object sender, EventArgs e)
    {
      tChart1.ShowEditor();
    }
Does this work ok at your end?
Thank you!

Christopher Ireland (Steema crew)
Please be aware of the newsgroup archives:
http://www.teechart.net/support/search.php
http://groups.google.com
http://codenewsfast.com/

Mike Jones
Advanced
Posts: 192
Joined: Thu Feb 01, 2007 12:00 am
Contact:

Your example works but mine doesn't

Post by Mike Jones » Thu Aug 14, 2008 7:05 pm

Found that the example TeeChart for .NET application at Welcome !\Datasets\Using the Designtime Editor. Press the "Edit DataSource button to bring up Chart Editor. Press the Data button. Notice there is nothing there.

Can you test with my example. It is uploaded it is in ChartBinding.zip.

Run the project and press the Bind #1 button. Then use the mouse to drag a point up or down. I would like to see the value in the datagridview to update after I drag a point.

While trying to understand the behavior of TChart I went to the Chart Editor dialog and wanted to look at the data to see if dragging points would update the data. In my example I see no points on the Data tab in the Chart Editor Dialog. I definitely see that the datagridview is not getting updated.

Is there an event that will fire after a user drags a point and then I can somehow refresh the datagridview with the new value?

I expected that if I data bound a TeeChart series to a datatable that dragging points would update the datatable automatically through the databinding. Obviously that is not working in my example

Mike Jones
Advanced
Posts: 192
Joined: Thu Feb 01, 2007 12:00 am
Contact:

Really in need of some suggestions

Post by Mike Jones » Tue Aug 19, 2008 2:01 pm

I really need the DragPoints tool to edit an underlying DataTable. I have a Steema.TeeChart.Styles.Line series bound to the datatable.

Also, I have the datatable bound to a datagridview. I have found a way to get the chart to update if I change a value in the datagridview. I would like the dragpoints to be used to edit the datatable as well. I really don't see any good way to do this.

I am hoping you might have some ideas on how I could do this. This need is very immediate for me. We do have the source code so if there are any suggestions you might have that might involve modifying our version of the source that would be great.

Pep
Site Admin
Site Admin
Posts: 3272
Joined: Fri Nov 14, 2003 5:00 am
Contact:

Post by Pep » Thu Aug 21, 2008 10:34 am

Hello Mike,

so, if I understand the problem is that the DataTable tool is not updated once a point has been dragged ? I've just tried it here using the latest v3 and worked fine.

Mike Jones
Advanced
Posts: 192
Joined: Thu Feb 01, 2007 12:00 am
Contact:

Not using the Data Table tool

Post by Mike Jones » Thu Aug 21, 2008 2:38 pm

I am talking about binding to a System.Data.DataTable where I bind the DataColumns to Line Series XValues.DataMember and YValues.DataMember. The Line Series DataSource property is set to the System.Data.DataTable.

Just as the sample of code above shows.

When I drag a point I want to underlying datasource to be updated. I should be able to look at the System.Data.DataTable and see the corresponding value to be updated. That is the definition of true databinding. It does not appear that TChart is implementing databinding fully. TChart will use the data source provided but TChart will not update that data source after a point has been dragged using the DragPoint tool.

Mike Jones
Advanced
Posts: 192
Joined: Thu Feb 01, 2007 12:00 am
Contact:

Very close to a solution

Post by Mike Jones » Thu Aug 21, 2008 5:04 pm

I stumbled upon the DragPoint Drag event. This event signature looks like

Code: Select all

dragPoint1_Drag(Steema.TeeChart.Tools.DragPoint sender, int index)
The Sender parameter has a member, Series, yet it is null even though there is a private variable called "theSeries" that is set to the series that the drag point tool is assigned to.

I found that I needed to set the Series property for the dragpoint tool, however it seems that if I didn't the dragpoint tool will operate on a series. It defaulted to some series, yet it the sender parameter gave me no way tell me what series it is operating on. It obviously knows internally but does not give me access to that information.

Any feedback would be appreciated.

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Post by Narcís » Mon Aug 25, 2008 9:47 am

Hello Mike,

I'm afraid what you request is not possible for now. I've added your request to the wish-list to be considered for inclusion in future releases.
Best Regards,
Narcís Calvet / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

Post Reply