I'm working a windows form application that generates a heat map of data points. I'm using a list of custom structures called "Pipes" that contain their own lists of data points. I then iterate over my list of lists as shown here:
foreach (NewPipe pipe in wall)
{
foreach (DataPoint x in pipe.returnPoints(xNum))
{
chart1.Series["Series1"].Points.Add(x);
}
xNum++;
}
While this works, it seems horribly inefficient. Also it would be nice if I could just update my list of lists and have the graph update, instead of having to clear it and re-graph it (or manually delete the removed data and etc). I'm familiar with the BindingList structure, is this the right tool to use and if so, how do you bind a list within a list to a chart? (Since I'm really after the data stored in a list in the lower tier list). Maybe I'm using the wrong structures entirely? (Though lists of lists actually matches how the data is generated fairly well).
Assuming you want to create a Heatmap which looks something like my examples here or here I'm afraid that using a
Chart
Control for this purpose may not be the best choice.While it is not impossible to use a
Charttype Point
to create it, it will have several problems..Most notable is the fact that you will have to create individual
DataPoints
for each point in the map.These are rather expensive
Series.MarkerSize
to a suitable number of pixels but you will have to adapt when you resize.You have asked about
DataBinding
to make the whole thing more efficient.You are using lists of list of
DataPoints
but:DataBinding
only binds values to the chart, not ready-madeDataPoints
This may not be a big problem if your X-Values are not important.
Well, there are many ways to use
DataBinding
with aChart
, both at theChart
and at theSeries
levels.And there is even one Points.DataBind overload that looks as if it would be suitable to bind Colors as is supports extended properties:
So the binding to a
DataView
should work like this:
However, while the
Labels
andToolTips
do indeed get bound, theDataPoint.Color
does not:This is disappointing; after all the DataPoint.Color is a
bindable
attribute. But it gets ignored.Here is a list of supported properties:
Conclusion: Afaik
DataBinding
will not let you set coloredDataPoints
. To make your code more effective using aChart
control, you can simply try usingchart1.SuspendLayout
andchart1.ResumeLayout
to make the setup happen all in one.However I would instead consider not using a Chart control in the first place.
The links to the two examples I gave in the first paragraph show two alternative ways:
The first one is all about drawing the heatmap in GDI+. This is really trivial and very efficient. (The details in the post are probebly not pertinent to your problem..) For simple scaling I suggest drawing into a
Bitmap
, which you assign to aPanel
orPictureBox
; create it in theClientSize
and set thePanel.ImageLayout
(or thePictureBox.SizeMode
) asStretch
.The second example uses the
Cells
of aDataGridView
as large 'pixels' for the heatmap...See the second link for a method to create a nice
List<Color>
!