<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	
	xmlns:georss="http://www.georss.org/georss"
	xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#"
	>

<channel>
	<title>.NET chart Archives - CenterSpace</title>
	<atom:link href="https://www.centerspace.net/tag/net-chart/feed" rel="self" type="application/rss+xml" />
	<link>https://www.centerspace.net/tag/net-chart</link>
	<description>.NET numerical class libraries</description>
	<lastBuildDate>Wed, 02 Mar 2016 18:40:56 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.1.1</generator>
<site xmlns="com-wordpress:feed-additions:1">104092929</site>	<item>
		<title>Using NMath with Microsoft Chart Controls for .NET</title>
		<link>https://www.centerspace.net/using-nmath-with-microsoft-chart-controls-for-net</link>
					<comments>https://www.centerspace.net/using-nmath-with-microsoft-chart-controls-for-net#respond</comments>
		
		<dc:creator><![CDATA[Ken Baldwin]]></dc:creator>
		<pubDate>Wed, 09 Mar 2011 11:04:53 +0000</pubDate>
				<category><![CDATA[NMath]]></category>
		<category><![CDATA[NMath Tutorial]]></category>
		<category><![CDATA[Visualization]]></category>
		<category><![CDATA[.NET chart]]></category>
		<category><![CDATA[.NET plotting]]></category>
		<category><![CDATA[C# charts]]></category>
		<category><![CDATA[C# ploting]]></category>
		<category><![CDATA[Chart Controls for .NET]]></category>
		<category><![CDATA[VB.NET charts]]></category>
		<category><![CDATA[VB.NET plotting]]></category>
		<guid isPermaLink="false">http://www.centerspace.net/blog/?p=3262</guid>

					<description><![CDATA[<p><img class="excerpt" title="chart2" src="https://www.centerspace.net/blog/wp-content/uploads/2011/03/chart2.png"  /> The Microsoft Chart Controls for .NET provide an easy (and free) solution for visualizing NMath numerical types. The Chart controls are available as a separate download for .NET 3.5. Beginning in .NET 4.0, the Chart controls are part of the .NET Framework. </p>
<p>The post <a rel="nofollow" href="https://www.centerspace.net/using-nmath-with-microsoft-chart-controls-for-net">Using NMath with Microsoft Chart Controls for .NET</a> appeared first on <a rel="nofollow" href="https://www.centerspace.net">CenterSpace</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>In 2007, Microsoft acquired the Dundas chart components, in order to deliver data visualization directly within Microsoft products. In October 2008, they released the Microsoft Chart Controls for .NET, which includes the Dundas ASP.NET and Windows Forms Chart controls. The Chart controls are available as a <a href="https://www.microsoft.com/en-us/download/details.aspx?id=14422">separate download for .NET 3.5</a>. Beginning in .NET 4.0, the Chart controls are part of the .NET Framework. To use the Chart controls, add a reference to System.Windows.Forms.DataVisualization.</p>
<p>A <strong>Chart</strong> object contains one or more <strong>ChartArea</strong>s, each of which contain one or more data <strong>Series</strong>. Each <strong>Series</strong> has an associated chart type, and a <strong>DataPoint</strong> collection. <strong>DataPoint</strong>s can be manually appended or inserted into the collection, or added automatically when a series is bound to a datasource using either the <tt>DataBindY()</tt> or <tt>DataBindXY()</tt> method. Since any <strong>IEnumerable</strong> can act as a datasource, it&#8217;s easy to use an NMath vector or vector view (of a matrix row or column, for example) as a datasource.</p>
<p>For example, suppose we want to create a scatter plot of the first two columns of a 20 x 5 <strong>DoubleMatrix</strong> (that is, column 0 vs. column 1).</p>
<pre lang="csharp">DoubleMatrix data = new DoubleMatrix( 20, 5, new RandGenUniform() );
DoubleVector x = data.Col( 0 );
DoubleVector y = data.Col( 1 );</pre>
<p>Begin by creating a new <strong>Chart</strong> object, and optionally adding a <strong>Title</strong>.</p>
<pre lang="csharp">Chart chart = new Chart()
{
  Size = new Size( 500, 500 ),
};

Title title = new Title()
{
  Name = chart.Titles.NextUniqueName(),
  Text = "My Data",
  Font = new Font( "Trebuchet MS", 12F, FontStyle.Bold ),
};
chart.Titles.Add( title );</pre>
<p>Next, add a <strong>ChartArea</strong>.</p>
<pre lang="csharp">ChartArea area = new ChartArea()
{
  Name = chart.ChartAreas.NextUniqueName(),
};
area.AxisX.Title = "Col 0";
area.AxisX.TitleFont = new Font( "Trebuchet MS", 10F, FontStyle.Bold );
area.AxisX.MajorGrid.LineColor = Color.LightGray;
area.AxisX.RoundAxisValues();
area.AxisY.Title = "Col 1";
area.AxisY.TitleFont = new Font( "Trebuchet MS", 10F, FontStyle.Bold );
area.AxisY.MajorGrid.LineColor = Color.LightGray;
area.AxisY.RoundAxisValues();
chart.ChartAreas.Add( area );</pre>
<p>Finally, add a new data <strong>Series</strong>, and bind the datasource to the NMath x,y vectors.</p>
<pre lang="csharp">Series series = new Series()
{
  Name = "Points",
  ChartType = SeriesChartType.Point,
  MarkerStyle = MarkerStyle.Circle,
  MarkerSize = 8,
};
series.Points.DataBindXY( x, y );
chart.Series.Add( series );</pre>
<p>To display the chart, we can use a utility function like this, which shows the given chart in a default form running in a new thread.</p>
<pre lang="csharp">public static void Show( Chart chart )
{
  Form form = new Form();
  form.Size = new Size( chart.Size.Width + 20, chart.Size.Height + 40 );
  form.Controls.Add( chart );
  Thread t = new Thread( () =&gt; Application.Run( form ) );
   t.Start();
}</pre>
<p>After calling</p>
<pre lang="csharp">Show( chart );</pre>
<p>the result looks like this:</p>
<p style="text-align: center;"><a href="https://www.centerspace.net/blog/wp-content/uploads/2011/03/chart11.png"><img decoding="async" class="size-full wp-image-3267 aligncenter" title="chart1" src="https://www.centerspace.net/blog/wp-content/uploads/2011/03/chart11.png" alt="Microsoft Chart Controls for .NET" width="491" height="486" srcset="https://www.centerspace.net/wp-content/uploads/2011/03/chart11.png 491w, https://www.centerspace.net/wp-content/uploads/2011/03/chart11-300x296.png 300w" sizes="(max-width: 491px) 100vw, 491px" /></a></p>
<p>Of course, you can easily plot more complicated data as well. For instance, suppose we fit a 4th degree polynomial to this (random) data:</p>
<pre lang="csharp">int degree = 4;
PolynomialLeastSquares pls = new PolynomialLeastSquares( degree, x, y );</pre>
<p>To add the fitted polynomial to the cart, just add a new data <strong>Series</strong> interpolating over the range of x values.</p>
<pre lang="csharp">Series series2 = new Series()
{
  Name = "Polynomial",
  ChartType = SeriesChartType.Line,
  MarkerStyle = MarkerStyle.None,
};
int numInterpolatedValues = 100;
double xmin = NMathFunctions.MinValue( x );
double xmax = NMathFunctions.MaxValue( x );
double step = ( xmax - xmin ) / ( numInterpolatedValues - 1 );
DoubleVector xi = new DoubleVector( numInterpolatedValues, xmin, step );
series2.Points.DataBindXY( xi, pls.FittedPolynomial.Evaluate( xi ) );
chart.Series.Add( series2 );</pre>
<p>Let&#8217;s also add a subtitle with the fitted function, and a <strong>Legend</strong>.</p>
<pre lang="csharp">Title subtitle = new Title()
{
  Name = chart.Titles.NextUniqueName(),
  Text = "f(x) = " + pls.FittedPolynomial.ToString( "N2" ),
};
chart.Titles.Add( subtitle );

Legend legend = new Legend()
{
  Name = chart.Legends.NextUniqueName(),
  DockedToChartArea = chart.ChartAreas[0].Name,
};
chart.Legends.Add( legend );</pre>
<p>Now the chart looks like this:<br />
<a href="https://www.centerspace.net/blog/wp-content/uploads/2011/03/chart2.png"><img decoding="async" loading="lazy" class="aligncenter size-full wp-image-3268" title="chart2" src="https://www.centerspace.net/blog/wp-content/uploads/2011/03/chart2.png" alt="" width="491" height="494" srcset="https://www.centerspace.net/wp-content/uploads/2011/03/chart2.png 491w, https://www.centerspace.net/wp-content/uploads/2011/03/chart2-150x150.png 150w, https://www.centerspace.net/wp-content/uploads/2011/03/chart2-298x300.png 298w" sizes="(max-width: 491px) 100vw, 491px" /></a></p>
<p>If you add a <strong>Chart</strong> control to your application using the visual designer (by dragging a <strong>Chart</strong> control from the Data category in the Toolbox), this generates code to create a default <strong>Chart</strong>, with a single <strong>ChartArea</strong>, <strong>Series</strong>, and <strong>Legend</strong>. You can then edit the properties in the Properties tab, and bind the generated <strong>Series</strong> to an NMath datasource. For example:</p>
<pre lang="csharp">public Form1()
{
  InitializeComponent();

  DoubleMatrix data = new DoubleMatrix( 20, 5, new RandGenUniform() );
  this.chart1.Series[0].Points.DataBindXY( data.Col(0), data.Col(1) );
}</pre>
<p>The Microsoft Chart Controls for .NET provide an easy (and free) solution for visualizing NMath numerical types.</p>
<p>Ken</p>
<p>The post <a rel="nofollow" href="https://www.centerspace.net/using-nmath-with-microsoft-chart-controls-for-net">Using NMath with Microsoft Chart Controls for .NET</a> appeared first on <a rel="nofollow" href="https://www.centerspace.net">CenterSpace</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.centerspace.net/using-nmath-with-microsoft-chart-controls-for-net/feed</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">3262</post-id>	</item>
	</channel>
</rss>
