This is a migrated thread and some comments may be shown as answers.

Using DataPointMember.XValue vs. DataPointMember.XCategory

4 Answers 122 Views
Chart
This is a migrated thread and some comments may be shown as answers.
Eric
Top achievements
Rank 1
Eric asked on 10 Sep 2010, 02:09 PM
I am binding my chart to a DataTable.  Using the following code in the chart's constructor to display two bar series works:

SeriesMapping histCostSeriesMapping = new SeriesMapping { LegendLabel = "Historic Cost", SeriesDefinition = new BarSeriesDefinition()};
histCostSeriesMapping.ItemMappings.Add(new ItemMapping("YEAR", DataPointMember.XCategory));
histCostSeriesMapping.ItemMappings.Add(new ItemMapping("HISTCOST", DataPointMember.YValue));
chart.SeriesMappings.Add(histCostSeriesMapping);
  
SeriesMapping replCostSeriesMapping = new SeriesMapping { LegendLabel = "Replacement Cost", SeriesDefinition = new BarSeriesDefinition()};
replCostSeriesMapping.ItemMappings.Add(new ItemMapping("YEAR", DataPointMember.XCategory));
replCostSeriesMapping.ItemMappings.Add(new ItemMapping("REPLCOST", DataPointMember.YValue));
chart.SeriesMappings.Add(replCostSeriesMapping);

chart.ItemsSource = _model.Data;


However, if I replace both instances of DataPointMember.XCategory with DataPointMember.XValue, I get the following error:

InvalidOperationException - The binary operator GreaterThanOrEqual is not defined for the types 'System.Object' and 'System.Double'.

Also if I use just one series on the chart (with DataPointMember.XValue), it works fine. 

4 Answers, 1 is accepted

Sort by
0
Yavor
Telerik team
answered on 15 Sep 2010, 08:24 AM
Hello Eric,

I tested the functionality, which you mentioned, and the control behaved as expected. Attached to this message, is the code, which I used for testing. You can take a look at it, and let me know whether this is the expected behavior. You can also use this as the initial setup, to replicate any erroneous behavior, and post the code back.

Greetings,
Yavor
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Eric
Top achievements
Rank 1
answered on 15 Sep 2010, 02:02 PM
Hi Yavor,

The example you provided only maps one data series, and it uses DataPointMember.XCategory instead of DataPointMember.XValue, so it does not demonstrate the issue I am having.

The modified code which replicates the error is as follows:

private void CheckBox_Checked(object sender, RoutedEventArgs e)
{
    //radChart.ItemsSource = TradeData.GetWeeklyData("MSFT");
    radChart.ItemsSource = TradeData.GetDataTable();
             
    mapping1 = new SeriesMapping();
    mapping1.SeriesDefinition = new LineSeriesDefinition();
              
    ItemMapping itemmapping1 = new ItemMapping("High", DataPointMember.YValue);            
    mapping1.ItemMappings.Add(itemmapping1);
    ItemMapping temp1 = new ItemMapping("Year", DataPointMember.XValue);
    mapping1.ItemMappings.Add(temp1);
  
    radChart.SeriesMappings.Add(mapping1);
  
    mapping2 = new SeriesMapping();
    mapping2.SeriesDefinition = new LineSeriesDefinition();
  
    ItemMapping itemmapping2 = new ItemMapping("Low", DataPointMember.YValue);
    mapping2.ItemMappings.Add(itemmapping2);
    ItemMapping temp2 = new ItemMapping("Year", DataPointMember.XValue);
    mapping2.ItemMappings.Add(temp2);
  
    radChart.SeriesMappings.Add(mapping2);
               
    radChart.Rebind();
}

public static DataTable GetDataTable() {
    DataTable tradeData = new DataTable("TradeData");
  
    DataColumn myColumn = new DataColumn();
    myColumn.DataType = System.Type.GetType("System.Int32");
    myColumn.AllowDBNull = false;
    myColumn.Caption = "Year";
    myColumn.ColumnName = "Year";
    tradeData.Columns.Add(myColumn);
    myColumn = new DataColumn();
    myColumn.DataType = System.Type.GetType("System.Decimal");
    myColumn.AllowDBNull = false;
    myColumn.Caption = "High";
    myColumn.ColumnName = "High";
    tradeData.Columns.Add(myColumn);
    myColumn = new DataColumn();
    myColumn.DataType = System.Type.GetType("System.Decimal");
    myColumn.AllowDBNull = false;
    myColumn.Caption = "Low";
    myColumn.ColumnName = "Low";
    tradeData.Columns.Add(myColumn);
  
    DataRow myRow;
    for (int i = 0; i < 100; i++) {
        myRow = tradeData.NewRow();
        myRow[0] = 1900 + i + 1;
        myRow[1] = i + 5;
        myRow[2] = i + 7;
        tradeData.Rows.Add(myRow);
    }
    return tradeData;
}

One thing to note is that the error does not occur if I map to an ObservableCollection, but it does occur if I map to a DataTable.
0
Ves
Telerik team
answered on 20 Sep 2010, 09:03 AM
Hi Eric,

Thanks for this  clarification. Indeed, when using DataTable you need to provide the field type for the item mappings. Please, find attached a small example which works as expected

Best regards,
Ves
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Eric
Top achievements
Rank 1
answered on 20 Sep 2010, 02:57 PM
Thanks, that works well.
Tags
Chart
Asked by
Eric
Top achievements
Rank 1
Answers by
Yavor
Telerik team
Eric
Top achievements
Rank 1
Ves
Telerik team
Share this question
or