Page 1 of 1

Supported datasources problem.

Posted: Thu Jan 20, 2011 8:53 am
by 9535597
Hi,

I'm evaluating the TeeChart .NET component for WPF and have been facing a few problems.
I tried an example from your forums:

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();
    }
But that ends up in an exception with error: Cannot bind to non-supported datasource.
Any tips for supported datasources? No DataSets or DataTables?

Re: Supported datasources problem.

Posted: Thu Jan 20, 2011 10:18 am
by 10050769
Hello NeoVesa,

I have made a simple example of DataSource in WPF. You can do something as next:

Code: Select all

public partial class Window1 : Window
    {
        public Window1()
        {
            InitializeComponent();
            InitializeChart();
        }
       private Steema.TeeChart.WPF.Styles.Bar Series1;
        private NameList observable;
        private void InitializeChart()
        {
            tChart1.Aspect.View3D = false;
            tChart1.Series.Add(Series1 = new Steema.TeeChart.WPF.Styles.Bar());

            Series1.XValues.DataMember = "DateOfBirth";
            Series1.YValues.DataMember = "Height";
            Series1.LabelMember = "LastName";
            Series1.ColorMember = "FavoriteColor";

            observable = new NameList();
            Series1.DataSource = observable;
        }
    }

    public class NameList : System.Collections.ObjectModel.ObservableCollection<Person>
    {
        public NameList()
            : base()
        {
            Add(new Person("Willa", "Cather", DateTime.Parse("09/22/1941"), Colors.Red, 171));
            Add(new Person("Isak", "Dinesen", DateTime.Parse("07/01/1964"), Colors.Green, 189));
            Add(new Person("Victor", "Hugo", DateTime.Parse("03/30/1987"), Colors.Blue, 196));
            Add(new Person("Jules", "Verne", DateTime.Parse("10/30/1995"), Colors.Orange, 175));
        }
    }

    public class Person
    {
        private string firstName;
        private string lastName;
        private DateTime dob;
        private Color favorite;
        private int height;

        public Person(string first, string last, DateTime dob, Color favorite, int height)
        {
            this.firstName = first;
            this.lastName = last;
            this.dob = dob;
            this.favorite = favorite;
            this.height = height;
        }

        public string FirstName
        {
            get { return firstName; }
            set { firstName = value; }
        }

        public string LastName
        {
            get { return lastName; }
            set { lastName = value; }
        }

        public DateTime DateOfBirth
        {
            get { return dob; }
            set { dob = value; }
        }

        public Color FavoriteColor
        {
            get { return favorite; }
            set { favorite = value; }
        }

        public int Height
        {
            get { return height; }
            set { height = value; }
        }
}
Could you please, tell us if previous example of DataSource works as you want?

I hope will helps.

Thanks,

Re: Supported datasources problem.

Posted: Thu Jan 20, 2011 11:10 am
by 9535597
Thanks for the quick answer Sandra,

that solution works just fine.
What i would want to do, is like in the example the DataSource is DataSet, but that doesn't work for me.
How would i set Dataset or DataTable as datasource?

Re: Supported datasources problem.

Posted: Fri Jan 21, 2011 10:10 am
by 10050769
Hello NeoVesa,

Could you check if next code works for you?

Code: Select all

        private Steema.TeeChart.WPF.Styles.Bar Series1;

        private void InitializeChart()
        {
            tChart1.Aspect.View3D = false;
            tChart1.Series.Add(Series1 = new Steema.TeeChart.WPF.Styles.Bar());

            System.Data.DataSet data = GetData();
            Series1.DataSource = data;
            Series1.XValues.DataMember = "ID";
            Series1.YValues.DataMember = "Y";
            Series1.LabelMember = "Name";
        }

        private System.Data.DataSet GetData()
        {
            System.Data.DataSet data = new System.Data.DataSet();
            System.Data.DataTable table = new System.Data.DataTable("Customers");

            table.Columns.Add("ID", typeof(int));
            table.Columns.Add("Y", typeof(double));
            table.Columns.Add("Name", typeof(string));

            data.Tables.Add(table);

            Random y = new Random();

            table.Rows.Add(1, y.Next(100), "Customer A");
            table.Rows.Add(2, y.Next(100), "Customer B");
            table.Rows.Add(3, y.Next(100), "Customer C");
            table.Rows.Add(4, y.Next(100), "Customer D");

            return data;
        }
If it doesn't work, please tell us exactly which is the problem? So we try to help to solve it.

Thanks,

Re: Supported datasources problem.

Posted: Mon Oct 03, 2011 6:56 am
by 15659385
Sandra, I can confirm the problems raised here. I have been unable to bind a ADO.NET DataTable to a TChart in a .NET 4 WPF XAML window. It should be very straightforward and is in the DemoProjectVB (which is TChart in Windows Forms). But your included WPF Demo has nothing to do with databinding in it. Exception thrown is: TeeChartException was unhandled: Cannot bind to non-supported datasource: sourceTable. This kind of thing should be fundamental to what your product can do and my company has paid the big bucks for this on my recommendation so I hope you can fix. I have the latest version installed (TeeChartNET2011_4.1.2011.07280)

XAML:

Code: Select all

<Window x:Class="MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="MainWindow" Height="350" Width="525" xmlns:my="clr-namespace:Steema.TeeChart.WPF;assembly=TeeChart.WPF">
    <Grid>
        <my:TChart HorizontalAlignment="Left" Name="TChart1" VerticalAlignment="Top" />
    </Grid>
</Window>


VB .NET Code Behind:

Code: Select all

Imports System.Data
Imports System.Drawing

Class MainWindow

    Private sourceTable As DataTable
    Private colXData As DataColumn
    Private colYData As DataColumn
    Private colDesc As DataColumn
    Private colColor As DataColumn

    Private Sub CreateTable()
        Dim r As New Random(255)

        ' Create DataTable
        sourceTable = New DataTable("sourceTable")
        colXData = New DataColumn("XData", Type.GetType("System.Double"))
        colYData = New DataColumn("YData", Type.GetType("System.Double"))
        colDesc = New DataColumn("Desc", Type.GetType("System.String"))
        colColor = New DataColumn("Color", Type.GetType("System.Object"))

        sourceTable.Columns.Add(colXData)
        sourceTable.Columns.Add(colYData)
        sourceTable.Columns.Add(colDesc)
        sourceTable.Columns.Add(colColor)

        ' Add table items.
        Dim NewRow As DataRow
        Dim lastVal As Double = 0
        Dim i As Integer
        For i = 0 To 9
            Dim cc As Color = Color.FromArgb(r.Next(255), r.Next(255), r.Next(255))
            NewRow = sourceTable.NewRow()
            NewRow("Desc") = "Label" + i.ToString()
            NewRow("XData") = lastVal
            NewRow("YData") = r.Next(10)
            NewRow("Color") = cc
            sourceTable.Rows.Add(NewRow)
            lastVal = lastVal + 5 + r.Next(5)
        Next i
    End Sub 'CreateTable


    Private Sub LoadData()
        TChart1(0).Clear()

        'include Labels
        'If checkBox1.Checked Then
        TChart1(0).LabelMember = colDesc.ToString()
        'Else
        'TChart1(0).LabelMember = ""
        'End If
        'include XValues
        'If checkBox2.Checked Then
        TChart1(0).XValues.DataMember = colXData.ToString()
        'Else
        'TChart1(0).XValues.DataMember = ""
        'End If
        TChart1(0).ColorMember = colColor.ToString()
        TChart1(0).YValues.DataMember = colYData.ToString()
        TChart1(0).DataSource = sourceTable
    End Sub 'LoadData

    Private Sub MainWindow_Loaded(sender As Object, e As System.Windows.RoutedEventArgs) Handles Me.Loaded
        Me.CreateTable()
        Me.TChart1.Series.Add(New Steema.TeeChart.WPF.Styles.Bar)
        Me.LoadData()
    End Sub
End Class

Re: Supported datasources problem.

Posted: Mon Oct 03, 2011 12:22 pm
by 10050769
Hello Jordan,
You are right! I can reproduce your problem here and I have added it in bug list report with number [TW16015770]. We will try to fix it for next maintenance releases of TeeChartWPF.
This kind of thing should be fundamental to what your product can do and my company has paid the big bucks for this on my recommendation so I hope you can fix. I have the latest version installed (TeeChartNET2011_4.1.2011.07280)
I have set bug (TW16015770) as serious severity, because problem is treated as soon as possible. Moreover, I recommend you to be aware at this forum, our RSS news feed, twitter and facebook accounts for new release announcements and what's implemented on them.

Thanks,

Re: Supported datasources problem.

Posted: Thu Oct 13, 2011 1:42 pm
by 10050769
Hello Jordan,


I inform you that the bug with number TW16015770 is not a bug. So after do many test we have found that you need add data when you use a DataSource using method Series.Add(data) if you want it works as you expected. I think you can do something as next:

Code: Select all

 private void InitializeChart()
        {
            tChart1.Aspect.View3D = false;
            tChart1.Series.Add(Series1 = new Steema.TeeChart.WPF.Styles.Bar());

            System.Data.DataTable data = GetData();
            //Series1.DataSource = data;
            Series1.XValues.DataMember = "ID";
            Series1.YValues.DataMember = "Y";
            Series1.LabelMember = "Name";
            Series1.Add(data);

        }


private System.Data.DataTable GetData()
        {
            System.Data.DataSet data = new System.Data.DataSet();
            System.Data.DataTable table = new System.Data.DataTable("Customers");

            table.Columns.Add("ID", typeof(int));
            table.Columns.Add("Y", typeof(double));
            table.Columns.Add("Name", typeof(string));

            data.Tables.Add(table);

            Random y = new Random();

            table.Rows.Add(1, y.Next(100), "Customer A");
            table.Rows.Add(2, y.Next(100), "Customer B");
            table.Rows.Add(3, y.Next(100), "Customer C");
            table.Rows.Add(4, y.Next(100), "Customer D");

            return table;
        }
Can you please tell us if previous code works as you expected?

I hope will helps.

Thanks,