0

I have BindingLists that store some objects I want to visualise on chart.

BindingList<Place> places; BindingList<Person> people; BindingList<Animal> animals; 

All of them implement following interface:

interface IMapObject { int getPositionX(); int getPositionY(); } 

How can I easily bind them all to single WinForms Point Chart? Every List need to be in separate Series. Chart should update automatically when I add new object to one of those lists.

2
  • What is Point Chart? Is that a native windows forms control? Commented Nov 11, 2017 at 15:03
  • @CodingYoshi it's System.Windows.Forms.DataVisualization.Charting.Chart, native windows form control configured to display points in 2D space Commented Nov 11, 2017 at 15:09

1 Answer 1

0

I have never worked with the Chart control before but I understand how binding works so I am pretty sure this will will work.

First change your interface to this:

interface IMapObject { int PositionX { get; set; } int PositionY { get; set; } } 

Implement that and then bind it like this:

ChartOne.Series.First().XValueMember = "PositionX"; ChartOne.Series.First().YValueMembers = "PositionY"; ChartOne.DataSource = places; 

As you can see strings are used to indicate the XValueMember and the YValueMembers, and therefore does not really take advantage of your interface and do Strongly Typed binding. The question you need to ask is if the effort is really worth it or to just go with strings. If you want the strongly typed binding, please see this thread for how it can be done (not directly related to charts but same idea). If I were you, I would just go with strings.

Sign up to request clarification or add additional context in comments.

6 Comments

Your answer describes how to bind one BindingList to one Chart. What if I wanted to assign three BindingLists to Data Source?
@Piotrek would that not be a different series?
yes, each of those lists will be in different series. But in your answer you take only places as DataSource. Moreover, I can't find any way to bind List directy to Series instead of entire chart.
@Piotrek Not sure what you mean. For another series you would write ChartOne.Series[1].XValueMember = "PositionX2"; ChartOne.Series[1].YValueMembers = "PositionY2". So your datasource will contain all the points for each series not just places.
I'm not sure what you mean too ^^ places is only one of three sets of data which I need to display on single chart. I also need to display people and animals (and points representing them need to look differently)
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.