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

[Solved] Specifying an indexed field/property for a series column

5 Answers 81 Views
Chart
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
John
Top achievements
Rank 1
John asked on 16 May 2012, 08:56 PM
I was unable to bind a DataTable to my MVC Chart control, so I converted the DataTable into an IEnumerable<Dictionary<string,object>> class.  I am able to bind it to my chart now; however, I am unable to specify the value column for an indexed property!

@(Html.Telerik().Chart(Model)
   .Name("chart")
   .Series(series => {
           series.Bar<string>(s => (string)s["Col1"]).Name("Representative Sales");
   })
   .CategoryAxis(axis => axis
       .Categories(s => s.Count)
   ))

I get the error:

Bound columns require a field or property access expression.


Basically, I am stuck.  How do I bind a DataTable to my MVC Chart control?  If that is not possible, then how do I specify an indexed property of a dictionary that I have converted the DataTable to, in order to bind it to the Chart control!? 

5 Answers, 1 is accepted

Sort by
0
Hristo Germanov
Telerik team
answered on 21 May 2012, 03:11 PM
Hi Joh,

The chart does not support data table binding and I am not sure that you can bind it with Dictionary<string,object> too. Can you try to bind the chart with List of objects?

All the best,
Hristo Germanov
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the Telerik Extensions for ASP.MET MVC, subscribe to their blog feed now.
0
Viktor
Top achievements
Rank 1
answered on 21 May 2012, 07:52 PM
Please send example.

Thank you,
0
Hristo Germanov
Telerik team
answered on 24 May 2012, 08:39 AM
Hello John,

Could you please examine the attached project and tell me if it works for you.

Regards,
Hristo Germanov
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the Telerik Extensions for ASP.MET MVC, subscribe to their blog feed now.
0
John
Top achievements
Rank 1
answered on 30 May 2012, 04:54 PM
Your example has a class in it that knows the property names ahead of time.  The problem is that I will not know this information at design time since the data is coming from a stored procedure that the user specifies on his database.  Therefore, you are able to specify one of these properties for the value/category, but I am unable to do that because I won't know them at compile time.
0
Hristo Germanov
Telerik team
answered on 01 Jun 2012, 01:55 PM
Hi John,

Can you examine this forum post and tell me if it works for you?

Regards,
Hristo Germanov
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the Telerik Extensions for ASP.MET MVC, subscribe to their blog feed now.
Tags
Chart
Asked by
John
Top achievements
Rank 1
Answers by
Hristo Germanov
Telerik team
Viktor
Top achievements
Rank 1
John
Top achievements
Rank 1
Share this question
or