{"id":1518,"date":"2016-05-31T10:21:01","date_gmt":"2016-05-31T10:21:01","guid":{"rendered":"http:\/\/mindfusion.eu\/blog\/?p=1518"},"modified":"2021-01-20T17:34:02","modified_gmt":"2021-01-20T17:34:02","slug":"surface-chart-in-wpf-with-data-biding-and-colour-map","status":"publish","type":"post","link":"https:\/\/mindfusion.dev\/blog\/surface-chart-in-wpf-with-data-biding-and-colour-map\/","title":{"rendered":"Surface Chart in WPF with Data Biding and Colour Map"},"content":{"rendered":"<p>This is a step-by-step guide on how to build a surface chart using MindFusion WPF Surface Chart control. The data is set with data binding. After we build the chart we&#8217;ll adjust some properties and preview how they affect the chart appearance.<\/p>\n<div id=\"attachment_1521\" style=\"width: 870px\" class=\"wp-caption alignnone\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-1521\" class=\"size-full wp-image-1521\" src=\"http:\/\/mindfusion.dev\/blog\/wp-content\/uploads\/2016\/05\/3d-scatter-chart.png\" alt=\"Step-by-step guide on how to build a 3D surface  or scatter chart\" width=\"860\" height=\"609\" srcset=\"https:\/\/mindfusion.dev\/blog\/wp-content\/uploads\/2016\/05\/3d-scatter-chart.png 860w, https:\/\/mindfusion.dev\/blog\/wp-content\/uploads\/2016\/05\/3d-scatter-chart-300x212.png 300w, https:\/\/mindfusion.dev\/blog\/wp-content\/uploads\/2016\/05\/3d-scatter-chart-768x544.png 768w, https:\/\/mindfusion.dev\/blog\/wp-content\/uploads\/2016\/05\/3d-scatter-chart-424x300.png 424w\" sizes=\"auto, (max-width: 860px) 100vw, 860px\" \/><p id=\"caption-attachment-1521\" class=\"wp-caption-text\">Step-by-step guide on how to build a 3D surface or scatter chart<\/p><\/div>\n<p><strong>I. General Settings<\/strong><\/p>\n<p>We start with a new WPF project and add the libraries needed for the WPF surface chart: MindFusion.Charting.Wpf and MindFusion.Licensing. We create a mapping to the charting namespace like that:<\/p>\n<pre>xmlns:chart=\"http:\/\/mindfusion.dev\/charting\/wpf\"\n<\/pre>\n<p>If you have installed the control or MindFusion WPF Pack with toolbox integration you&#8217;ll just need to drag and drop the surface chart control.<\/p>\n<div id=\"attachment_1525\" style=\"width: 330px\" class=\"wp-caption alignnone\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-1525\" class=\"size-full wp-image-1525\" src=\"http:\/\/mindfusion.dev\/blog\/wp-content\/uploads\/2016\/05\/visual-studio-surface-chart-control.png\" alt=\"Drag and drop the surface chart control\" width=\"320\" height=\"174\" srcset=\"https:\/\/mindfusion.dev\/blog\/wp-content\/uploads\/2016\/05\/visual-studio-surface-chart-control.png 320w, https:\/\/mindfusion.dev\/blog\/wp-content\/uploads\/2016\/05\/visual-studio-surface-chart-control-300x163.png 300w\" sizes=\"auto, (max-width: 320px) 100vw, 320px\" \/><p id=\"caption-attachment-1525\" class=\"wp-caption-text\">Drag and drop the surface chart control<\/p><\/div>\n<p>Next step is to declare the Surface Chart. We do this in XAML:<\/p>\n<pre id=\"line1\">&lt;<span class=\"start-tag\">chart:surfacechart<\/span> <span class=\"attribute-name\">x:name<\/span>=\"<a class=\"attribute-value\">surfaceChart<\/a>\" <span class=\"attribute-name\">effect3d<\/span>=\"<a class=\"attribute-value\">ShaderEffect<\/a>\" <span class=\"attribute-name\">scatterfacesize<\/span>=\"<a class=\"attribute-value\">1<\/a>\" <span class=\"attribute-name\">showsurface<\/span>=\"<a class=\"attribute-value\">True<\/a>\" <span class=\"attribute-name\">showwireframe<\/span>=\"<a class=\"attribute-value\">True<\/a>\" <span class=\"attribute-name\">showscatters<\/span>=\"<a class=\"attribute-value\">False<\/a>\" <span class=\"attribute-name\">title<\/span>=\"<a class=\"attribute-value\">ScatterChart3D<\/a>\" <span class=\"attribute-name\">sidewallthickness<\/span>=\"<a class=\"attribute-value\">0.5<\/a>\" <span class=\"attribute-name\">interpolationtype<\/span>=\"<a class=\"attribute-value\">Bezier<\/a>\" <span class=\"attribute-name\">gridtype<\/span>=\"<a class=\"attribute-value\">Horizontal<\/a>\" <span class=\"attribute-name\">scale<\/span>=\"<a class=\"attribute-value\">200<\/a>\" <span class=\"attribute-name\">groundlevel<\/span>=\"<a class=\"attribute-value\">0<\/a>\"&gt;\n<span id=\"line256\"><\/span>&lt;\/<span class=\"end-tag\">chart:surfacechart<\/span>&gt;<\/pre>\n<p>We use a <a href=\"http:\/\/www.mindfusion.dev\/onlinehelp\/wpfchart\/index.htm?T_MindFusion_Charting_Wpf_ChartEffect3D.htm\">ShaderEffect<\/a> to make the chart more beautiful. The <a href=\"http:\/\/www.mindfusion.dev\/onlinehelp\/wpfchart\/index.htm?P_MindFusion_Charting_Wpf_SurfaceChart_ShowSurface_0.htm\">ShowSurface<\/a> property means the control shall draw a surface but will not draw a wireframe or scatters &#8211; we&#8217;ll change that later. The <a href=\"http:\/\/www.mindfusion.dev\/onlinehelp\/wpfchart\/index.htm?P_MindFusion_Charting_Wpf_SurfaceChart_SideWallThickness_0.htm\">SideWallThickness<\/a> sets how the walls will look &#8211; we make them modestly thick. If we don&#8217;t set a <a href=\"http:\/\/www.mindfusion.dev\/onlinehelp\/wpfchart\/index.htm?P_MindFusion_Charting_Wpf_AxesChart3D_GridType_0.htm\">GridType<\/a> it will be more difficult to read the chart, so we set a horizontal grid. Scale determines how the chart will be zoomed and <a href=\"http:\/\/www.mindfusion.dev\/onlinehelp\/wpfchart\/index.htm?P_MindFusion_Charting_Wpf_SurfaceChart_GroundLevel_0.htm\">GroundLevel<\/a> sets the location of the bottom or ground wall.<\/p>\n<p><strong>II. Data Binding<\/strong><\/p>\n<p>We&#8217;ll use a single series in the chart and we initialize it in XAML as well:<\/p>\n<pre id=\"line1\">&lt;<span class=\"start-tag\">chart:surfaceseries<\/span> <span class=\"attribute-name\">x:name<\/span>=\"<a class=\"attribute-value\">series1<\/a>\"&gt;\n<span id=\"line261\"><\/span>&lt;\/<span class=\"end-tag\">chart:surfaceseries<\/span>&gt;<\/pre>\n<p>For the purpose of this sample we create just a List of Point3D objects, which will be the data source. We do this in code.<\/p>\n<pre>List Data = new List();\nPoint3D point3D;\n\nfor (int i = 0; i &lt; 360; i+=10)\n{\ndouble angle_rad = i \/ 180.0 * Math.PI;\n\nfor (int r = 0; r &lt;= 10; r++)\n{\ndouble radius = r * 0.2;\ndouble x = radius * Math.Cos(angle_rad);\ndouble z = radius * Math.Sin(angle_rad);\n\npoint3D = new Point3D(x, radius, z);\nData.Add(point3D);\n }\n}\n\n<\/pre>\n<p>We generate the points using the algorithm for a cone. Now let&#8217;s bind the data list to the chart&#8217;s properties.<\/p>\n<pre>surfaceChart.DataSource = Data;\nseries1.XDataPath = \"X\";\nseries1.YDataPath = \"Y\";\nseries1.ZDataPath = \"Z\";\n<\/pre>\n<p>The <a href=\"http:\/\/www.mindfusion.dev\/onlinehelp\/wpfchart\/index.htm?T_MindFusion_Charting_Wpf_AxesSeries3D_Members.htm\">DataPath<\/a> properties specify the names of each data bound property.<\/p>\n<p>Now that we know our data we must set the minimum and maximum value of all three chart axes to make sure data is rendered correctly:<\/p>\n<pre>surfaceChart.XAxisSettings.MinValue = -2;\nsurfaceChart.XAxisSettings.Interval = 0.4;\nsurfaceChart.XAxisSettings.MaxValue = 2;\nsurfaceChart.YAxisSettings.MinValue = 0;\nsurfaceChart.YAxisSettings.MaxValue = 2;\nsurfaceChart.YAxisSettings.Interval = 0.4;\nsurfaceChart.ZAxisSettings.MinValue = -2;\nsurfaceChart.ZAxisSettings.MaxValue = 2;\nsurfaceChart.ZAxisSettings.Interval = 0.4;\n<\/pre>\n<p>Each axis exposes <a href=\"http:\/\/www.mindfusion.dev\/onlinehelp\/wpfchart\/index.htm?P_MindFusion_Charting_Wpf_AxisSettings_MinValue_0.htm\">MinValue<\/a>, <a href=\"http:\/\/www.mindfusion.dev\/onlinehelp\/wpfchart\/index.htm?P_MindFusion_Charting_Wpf_AxisSettings_MaxValue_0.htm\">MaxValue<\/a> and <a href=\"http:\/\/www.mindfusion.dev\/onlinehelp\/wpfchart\/index.htm?P_MindFusion_Charting_Wpf_AxisSettings_Interval_0.htm\">Interval<\/a> properties, which are used to define the scale.<\/p>\n<p><strong>III. Colours<\/strong><\/p>\n<p>The colours for a surface chart are set with the <a href=\"http:\/\/www.mindfusion.dev\/onlinehelp\/wpfchart\/index.htm?P_MindFusion_Charting_Wpf_ChartSeries_Fills_0.htm\">Fills<\/a> property. In a surface chart, if you use a gradient brush, each point will read its color mapped to the matching position on the gradient. If you want more details, you can use the <a href=\"http:\/\/www.mindfusion.dev\/onlinehelp\/wpfchart\/index.htm?P_MindFusion_Charting_Wpf_SurfaceChart_TextureType_0.htm\">TextureType<\/a> and <a href=\"http:\/\/www.mindfusion.dev\/onlinehelp\/wpfchart\/index.htm?P_MindFusion_Charting_Wpf_SurfaceChart_ColorMapList_0.htm\">ColorMapList<\/a> properties to specify the colour map. In our sample we use XAML and add a gradient brush:<\/p>\n<pre id=\"line1\">&lt;<span class=\"start-tag\">chart:surfaceseries.fills<\/span>&gt;\n<span id=\"line305\"><\/span> \t&lt;<span class=\"start-tag\">lineargradientbrush<\/span> <span class=\"attribute-name\">startpoint<\/span>=\"<a class=\"attribute-value\">0,0<\/a>\" <span class=\"attribute-name\">endpoint<\/span>=\"<a class=\"attribute-value\">0,1<\/a>\"&gt;\n<span id=\"line306\"><\/span>&lt;<span class=\"start-tag\">gradientstop<\/span> <span class=\"attribute-name\">color<\/span>=\"<a class=\"attribute-value\">#D2D9A3<\/a>\" <span class=\"attribute-name\">offset<\/span>=\"<a class=\"attribute-value\">0<\/a>\"&gt;\n<span id=\"line307\"><\/span>&lt;<span class=\"start-tag\">gradientstop<\/span> <span class=\"attribute-name\">color<\/span>=\"<a class=\"attribute-value\">#023E73<\/a>\" <span class=\"attribute-name\">offset<\/span>=\"<a class=\"attribute-value\">0.33<\/a>\"&gt;\n<span id=\"line308\"><\/span>&lt;<span class=\"start-tag\">gradientstop<\/span> <span class=\"attribute-name\">color<\/span>=\"<a class=\"attribute-value\">#8A188C<\/a>\" <span class=\"attribute-name\">offset<\/span>=\"<a class=\"attribute-value\">0.66<\/a>\"&gt;\n<span id=\"line309\"><\/span>&lt;<span class=\"start-tag\">gradientstop<\/span> <span class=\"attribute-name\">color<\/span>=\"<a class=\"attribute-value\">#F24B6A<\/a>\" <span class=\"attribute-name\">offset<\/span>=\"<a class=\"attribute-value\">1.0<\/a>\"&gt;\n<span id=\"line310\"><\/span>&lt;\/<span class=\"end-tag\">gradientstop<\/span>&gt;&lt;\/<span class=\"end-tag\">gradientstop<\/span>&gt;&lt;\/<span class=\"end-tag\">gradientstop<\/span>&gt;&lt;\/<span class=\"end-tag\">gradientstop<\/span>&gt;&lt;\/<span class=\"end-tag\">lineargradientbrush<\/span>&gt;\n<span id=\"line311\"><\/span>&lt;\/<span class=\"end-tag\">chart:surfaceseries.fills<\/span>&gt;<\/pre>\n<p><strong>IV. Customizations<\/strong><\/p>\n<p>We can show a wire frame by setting <a href=\"http:\/\/www.mindfusion.dev\/onlinehelp\/wpfchart\/index.htm?P_MindFusion_Charting_Wpf_SurfaceChart_ShowWireFrame_0.htm\">ShowWireFrame<\/a> to &#8220;true&#8221;. If we want to show scatters, we&#8217;d better turn off <a href=\"http:\/\/www.mindfusion.dev\/onlinehelp\/wpfchart\/index.htm?P_MindFusion_Charting_Wpf_SurfaceChart_ShowSurface_0.htm\">ShowSurface<\/a> and set <a href=\"http:\/\/www.mindfusion.dev\/onlinehelp\/wpfchart\/index.htm?P_MindFusion_Charting_Wpf_SurfaceChart_ShowScatters_0.htm\">ShowScatters<\/a> to true. A wire frame can be show no matter the surface type. You can combine all of them &#8211; scatters, wire frame and surface.<\/p>\n<p><a href=\"http:\/\/www.mindfusion.dev\/onlinehelp\/wpfchart\/index.htm?P_MindFusion_Charting_Wpf_SurfaceChart_InterpolationType_0.htm\">InterpolationType<\/a> lets you choose among various types of interpolation. Choosing None means that the control shall simply connect the 3D points.<\/p>\n<p>An important property is <a href=\"http:\/\/www.mindfusion.dev\/onlinehelp\/wpfchart\/index.htm?P_MindFusion_Charting_Wpf_SurfaceChart_PointMergeThreshold_0.htm\">PointMergeThreshold<\/a> &#8211; it indicates the smallest difference at which a point that comes too close to another point won&#8217;t be drawn. If we set it to 0 or a negative number all points will be drawn.<\/p>\n<p>Here is a selection of images of charts with different combination of surface properties turned on: wire frame, surface, scatters.<\/p>\n<div id=\"attachment_1523\" style=\"width: 1010px\" class=\"wp-caption alignnone\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-1523\" class=\"size-full wp-image-1523\" src=\"http:\/\/mindfusion.dev\/blog\/wp-content\/uploads\/2016\/05\/surface-chart-types.png\" alt=\"By turning a single property you can completely change the appearance of a 3D surface chart\" width=\"1000\" height=\"657\" srcset=\"https:\/\/mindfusion.dev\/blog\/wp-content\/uploads\/2016\/05\/surface-chart-types.png 1000w, https:\/\/mindfusion.dev\/blog\/wp-content\/uploads\/2016\/05\/surface-chart-types-300x197.png 300w, https:\/\/mindfusion.dev\/blog\/wp-content\/uploads\/2016\/05\/surface-chart-types-768x505.png 768w, https:\/\/mindfusion.dev\/blog\/wp-content\/uploads\/2016\/05\/surface-chart-types-457x300.png 457w\" sizes=\"auto, (max-width: 1000px) 100vw, 1000px\" \/><p id=\"caption-attachment-1523\" class=\"wp-caption-text\">By turning a single property you can completely change the appearance of a 3D surface chart<\/p><\/div>\n<p>You can download the sample directly from this link:<\/p>\n<p align=\"center\"><a href=\"https:\/\/mindfusion.dev\/_samples\/SurfaceChartTutorial.zip\">Download MindFusion Surface Chart Tutorial<\/a><\/p>\n<p>Learn more about the WPF Chart &amp; Gauge control <a href=\"http:\/\/mindfusion.dev\/wpfchart.html\">here.<\/a><\/p>\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>This is a step-by-step guide on how to build a surface chart using MindFusion WPF Surface Chart control. The data is set with data binding. After we build the chart we&#8217;ll adjust some properties and preview how they affect the &hellip; <a href=\"https:\/\/mindfusion.dev\/blog\/surface-chart-in-wpf-with-data-biding-and-colour-map\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","enabled":false},"version":2}},"categories":[61,74],"tags":[393,256,394],"class_list":["post-1518","post","type-post","status-publish","format-standard","hentry","category-charting-2","category-sample-code","tag-3d-scatter-chart","tag-surface-chart","tag-surface-chart-with-colour-map"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p3RlKs-ou","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/mindfusion.dev\/blog\/wp-json\/wp\/v2\/posts\/1518","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mindfusion.dev\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mindfusion.dev\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mindfusion.dev\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/mindfusion.dev\/blog\/wp-json\/wp\/v2\/comments?post=1518"}],"version-history":[{"count":9,"href":"https:\/\/mindfusion.dev\/blog\/wp-json\/wp\/v2\/posts\/1518\/revisions"}],"predecessor-version":[{"id":2588,"href":"https:\/\/mindfusion.dev\/blog\/wp-json\/wp\/v2\/posts\/1518\/revisions\/2588"}],"wp:attachment":[{"href":"https:\/\/mindfusion.dev\/blog\/wp-json\/wp\/v2\/media?parent=1518"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mindfusion.dev\/blog\/wp-json\/wp\/v2\/categories?post=1518"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mindfusion.dev\/blog\/wp-json\/wp\/v2\/tags?post=1518"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}