heat map control - c#

i am looking for a winforms solution for a heatmap control. Essentially if i have a bunch of sales data and i have different dimensions (region for example), i want to visualize the profit and loss per region and also factor in the size of the region.
Similar to this:
http://www.smartmoney.com/etf/maps/
does anyone recommend a third party control or other suggestion to get this done quick.

Dundas Charts has a Heat Map option.
http://www.dundas.com/Gallery/Flash/Chart/Other/index.aspx

Related

How to render dynamic data in a custom WPF control, such as a line graph?

I'm working on a LineGraph control which consists many DependencyProperties that affect how the control should display its data. For example, the control contains the following properties to affect its axes:
AxisStroke - Color of the axes.
AxisThickness - Stroke thickness of the axes.
It also contains properties for display numbers & tick marks
VerticalTicks - True/False to indicate whether or not ticks appear along the vertical axis
HorizontalTicks - True/False to indicate whether or not ticks appear along the horizontal axis
VerticalMin - Minimum value on the vertical axis (numeric)
VerticalStep - The distance in between each vertical tick
VerticalMax - Maximum value on the vertical axis (numeric)
HorizontalMin - Minimum value on the horizontal axis (numeric)
HorizontalStep - The distance in between each horizontal tick
HorizontalMax - Maximum value on the horizontal axis (numeric)
And many more properties exist to allow for different line styles on a single graph (LineColor, LineThickness, DataPointShape, and DataPointIcon to name a few).
My goal is to be able to call out my LineGraph in XAML to insert it into a Window. I would like to be able to specify each of these settings inside the XAML as well, and see the new rendered image of the control in the WPF designer.
Now, given there is a lot of geometric shapes to render on the LineGraph, I though using a Canvas would be a good choice to render the data. Unfortunately, when I'm working in XAML, I cannot perform computations for the locations of shapes based on the control's width & height.
And yes, the shapes' locations must be computed because the data points for the graph are dynamic and the tick-related information is dynamic. Not to mention, I would like to display the actual values along each axis of the LineGraph.
So, I thought I might be able to display this control as if I was doing the rendering in C# code. Other windowing frameworks sometimes provide a Render method that can be used for laying out all of the sub-components.
Doing this, however, doesn't seem possible since WPF relies heavily on XAML for the visual appearance of controls. Also, requiring that the WPF designer must display the LineGraph based on the properties and data specified, it doesn't seem like C# code would solve the problem.
I suppose my questions are these:
How can I render data dynamically inside of a WPF control?
Am I able to specify in C# how my control is rendered, allowing the WPF designer to reflect it?
Side Note:
I've done quite a bit of research, but I am only finding information on how to implement more simple types of controls. If you know of any references that contain information on this topic, please feel free to post them in addition to your answers. I will be more than happy to learn how to do this completely.
EDIT:
I've created a graph using Excel to elaborate what the LineGraph control might look like if it has correct data and properties.
I will answer this based on my experience on implementing custom built graphing libraries in WIN32, WinForm, WPF, WinCE, WP8+WinRT, ....and even on a FPGA :)
It's extremely difficult to implement one from scratch. It may seem easy at first but you will run into a lot of "What should I do if this happens?". For example, in your above graph it seems you got a DataPoint # (5,100) it graphs it pretty well. But lets say, I add another DataPoint # (5.000000005, 0). How would you handle that in your code? Would you say that each pixel on the graph represents an exact value on the X-Axis, or does each pixel represent a range of X-Values?
I would recommend that you use an already establish library to do what you want to do unless you need something very specific like lets say you need horizontal cursors on the graph (think Tektronix Oscilloscope) and you need to calculate some values in between the two cursors.. then maybe you need to implement your own custom one or build on top of an open source one.
So, if you are still adamant of creating your own custom control here are answers to your questions.
How can I render data dynamically inside of a WPF control?
You can use a WriteableBitmap and create your own primitive drawing library from that. After you're done rendering, set it as the ImageSource of your control.
Or you can use WriteableBitmapEx which has GDI like drawing functions already implemented for you.
WriteableBitmapEx CodePlex Page, I also think you can just get it from NuGet as well.
You can also use a <Canvas> and add UI elements to that as well.
Am I able to specify in C# how my control is rendered, allowing the WPF designer to reflect it?
This depends on how you create your controls, but yes you can create Properties in your custom control that will appear in the Designer. Allowing you to change it thus updating the display. I would read a lot of tutorials about writing your own custom user control library. They can explain it better than I can in a SO answer. If you implement the properties correctly it should like so.....
Full Size Image: http://i.stack.imgur.com/pmevo.png
After changing the Number of Rows from 15 to 10 and the starting Y offset to -1 (thus moving the graph up and making the rows a lot taller)
Full Size Image: http://i.stack.imgur.com/0RKnA.png

How to refresh the chart very quickly if I have a very large number of data to be shown in Microsoft Chart

I am using C#, and would like to plot a line chart to visualize my data, the data could be stored as a double array, the number could be very large, over 100000 maybe, and I also would like to update the data source all the time, but when I use the Microsoft Win Chart, the refresh rate will be very slow if the number is too large (20000 would give a very bad user experience), I use the FastLine/FastPoint chartType, but it did not give me too much improvement, and I also tried to directly bind the data to the Points.DataBindY method, still, does not feel very well.
Is there anyone has experience on how to deal with this?
Many thanks.
You're going to find that trying to chart that number of points (100k) is going to overwhelm even the most powerful of charting controls. And I would question why it's even necessary to do that. How can you possibly differentiate 100k points on a chart? It seems unnecessary. Most charting controls (I'm most familiar with WPF controls) allow you to 'sample' the data (via a sampling threshold). This permits you to still retain the general shape of the data, but do so with far fewer data points, and much better performance.
Also, be very careful when binding data. With many charting controls, when you bind data, each data point bound to the chart causes a refresh of the chart. You can imagine what 100k refreshes would do :(. If you can, find a way to refresh the chart after all the data has been bound to the chart.
A solution might be to reduce the scale to 1:10000, greatly reducing drawn points while keeping the same draw.
You could do this by working on the data array before giving it to the chart.
try this:
chart1.Series[0].ChartType = SeriesChartType.FastLine;
or
chart1.Series[0].ChartType = SeriesChartType.FastPoint;
In cases when you need to draw more than 100,000 data points you may also consider using FastLine and FastPoint chart types. They do not support all the features of the regular Line and Point chart but will SIGNIFICANTLY improve chart performance.
https://blogs.msdn.microsoft.com/alexgor/2008/12/02/microsoft-chart-control-how-to-improve-chart-performance/
for other type of charts . idk either.
Tried to leave as a comment but can't due to rep, to update the chart manually every 'x' many points:
https://stackoverflow.com/a/10621610/1360625
Has a massive effect on speed and efficiency.

High performance plot control in WPF

I am doing some work for which I need to develop a control, it should be a simple graph that shows several points and two edges.
My problem is that I need to show up to 16k points, with an update rate of 30 Hz. Has anyone done something similar?, and has any advice?.
For example whether to inherit from FrameworkElement or Control (ItemsControl in this case). If the control inherits from FrameworkElememt it may have a better performance drawing the points in the OnRender method but I would miss the Templating feature that comes from inheriting from Control.
Or does there exist another control that can do this out there?
Thanks in advance for your time.
I ended up using InteropBitmap, it is the fatest bitmap rendering class from WPF.
It allows you to map the image that you want to paint (in memory) and then reder it as a Image. This was perfect as i needed to plot points on the screen.
I got great performance (almost 50Hz for 20k points), i also use PLINQ to update the points in memory.
check this article for more details...
Try and read about ZoomableCanvas. I believe it can solve your problem. You can render all the points as small rectangles/ellipses inside the ZoomableCanvas.

WPF - Dynamically rearrange control hierarchy

How is it possible to dynamically fill a container? Let's say to fill a big circle with small circles, recursively. Just fill the space fine.
I would like to use it for data hierarchy display.
To make it clear:
If you want something off the shelf, have a look at Graph#
http://graphsharp.codeplex.com/
videos here:
Simple usage scenario
http://www.youtube.com/watch?v=VTbuvkaPGxE
Data Visualization with Graph#
http://www.youtube.com/watch?v=agDPDzqB4o0&feature=related
It does dynamic graph layout and is fairly easy to use. There are a choice of layout algorithms [see sample app] each of which are configurable.
however filling until an area is "full" is not something that'll work out of the box. Although you could for example create a graph, lay it out & then measure the ratio between the size of a vertex and the size of the whole graph, then add or remove vertexes until you hit upon your desired density. I would hazard you could pretty quickly by trial and error come up with a quick and dirty forumula between the size of canvas to fill & the number of vertexes you should add.
Note that you can customise the vertex templates pretty easily to be any kind of data [this is standard wpf but Graph# specific examples can be found on http://graphsharp.codeplex.com/discussions ]
if you wanted to code your own layout you might like to have a look at some of the techniques Graph# use... for example a dynamic zoom component the source for which is available here: http://wpfextensions.codeplex.com/
hope that helps a little

wpf custom control: audiowaveform rectangle with selection slider

I'm working on a c# wpf app in which I want to do something with audio. the irrklang audio library provides me with a pcm decoded 16 bit byte array.
I want to create a timeline control which shows the waveform along the timeline with an overlaying rectangle which the user can drag and click/drag the left and right side to increase or decrease the selection.
It is used to the trim the audio track. I would like the selected min and max to be databindable, the minimum and maximum value of the total track to be bindable.
To clarify here is an image mockup:
I'm not asking for a complete control but tips and suggestions on how to tackle this are more than welcome. Perhaps solutions like this already exist but so far I haven't been able to find it.
I think I need to tackle: the control (zooming, panning and changing the selection) and drawing the waveform in the control
Thanks in advance,
I think you should check out this codeplex project
http://wpfsvl.codeplex.com/
Refer to Audio WaveForm Drawing Using WPF.
Something based upon WaveFileTrimmerControl.xaml would be useful, it uses related controls PolygonWaveFormControl.xaml & RangeSelectionControl.xaml (links are to the XAML but refer to the CS also). In any case it'd be a good starting point for building a control that exactly meets what you want.
You could override the render method and use primitives which will give possibly better performance; but like anything related to performance I'd try the above approach first which is almost certainly good enough.

Categories