Page 1 of 1

Only one curve is drawn (Direct2D)

Posted: Thu Nov 13, 2014 2:43 pm
by 15667696
Why is only one curve shown in teechart, when I put 4 fastline curves into teechart ? Direct2D is used with windows forms host.
The curves should be printed to put on top of each other and not one below the other.

Code:
Xaml MainWindow:

Code: Select all

<Window x:Class="WpfApplication9.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"		
        Title="MainWindow" Height="350" Width="525">
    <Grid>
		<Grid Name="WindowsFormHostGrid"/>	
	</Grid>
</Window>
Behind:

Code: Select all

using System;
using System.Windows;
using System.Windows.Threading;
using Steema.TeeChart;
using Steema.TeeChart.Drawing;
using Steema.TeeChart.Drawing.Direct2D;
using Steema.TeeChart.Styles;


namespace WpfApplication9
{
	/// <summary>
	/// Interaction logic for MainWindow.xaml
	/// </summary>
	public partial class MainWindow : Window
	{
		private TChart _tChart1;

		private FastLine _fastLineSeries1;
		private FastLine _fastLineSeries2;
		private FastLine _fastLineSeries3;
		private FastLine _fastLineSeries4;

		private const int NumPoints = 100000;

		/// <summary>
		/// 
		/// </summary>
		public MainWindow()
		{
			InitializeComponent();
			Loaded += MainWindow_Loaded;
		}
		
		/// <summary>
		/// 
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		void MainWindow_Loaded(object sender, RoutedEventArgs e)
		{
			_tChart1 = new TChart();

			var D2D = new Graphics3DDirect2D(_tChart1.Chart);

			D2D.TextRenderingHint = System.Drawing.Text.TextRenderingHint.SingleBitPerPixel;
			D2D.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighSpeed;

			_tChart1.Graphics3D = D2D;
			_tChart1.Graphics3D.BufferStyle = BufferStyle.None;
			_tChart1.Aspect.View3D = false;

			_tChart1.Walls.Visible = false;
			_tChart1.Legend.Visible = false;
			_tChart1.Header.Visible = false;

			_tChart1.Panel.Pen.UseStyling = false;
			_tChart1.Panel.Bevel.Inner = BevelStyles.None;
			_tChart1.Panel.Bevel.Outer = BevelStyles.None;
			
			// Create the interop host control.
			var host = new System.Windows.Forms.Integration.WindowsFormsHost();
			host.Child = _tChart1;		

			WindowsFormHostGrid.Children.Add(host);

			_fastLineSeries1 = new FastLine();			
			_fastLineSeries1.LinePen.Color = System.Drawing.Color.Blue;			
			_tChart1.Chart.Series.Add(_fastLineSeries1);

			_fastLineSeries2 = new FastLine();
			_fastLineSeries2.LinePen.Color = System.Drawing.Color.Brown;						
			_tChart1.Chart.Series.Add(_fastLineSeries2);

			_fastLineSeries3 = new FastLine();			
			_tChart1.Chart.Series.Add(_fastLineSeries3);		
			_fastLineSeries3.LinePen.Color = System.Drawing.Color.BlueViolet;

			_fastLineSeries4 = new FastLine();			
			_tChart1.Chart.Series.Add(_fastLineSeries4);			
			_fastLineSeries4.LinePen.Color = System.Drawing.Color.Chartreuse;
			
			// Set bottom axis
			_tChart1.Axes.Bottom.Automatic = false;
			_tChart1.Axes.Bottom.SetMinMax(0, NumPoints);

		
			const int graphTimerTick = 50; // 50 ms
			var graphTimer = new DispatcherTimer();
			graphTimer.Tick += OnGraphTimerTick;
			graphTimer.Interval = new TimeSpan(0, 0, 0, 0, graphTimerTick);
			graphTimer.IsEnabled = true;
		}

		/// <summary>
		/// 
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		private void OnGraphTimerTick(object sender, EventArgs e)
		{
			_tChart1.AutoRepaint = false;

			var myX = new double[NumPoints];
			var myY = new double[NumPoints];

			for (int i = 0; i < 4; i++)
			{
				var r = new Random();
				double tmp = r.NextDouble() * 10000;
				for (int t = 0; t < NumPoints; t++)
				{
					tmp += r.Next(100) - 49.5;
					myX[t] = t;
					myY[t] = tmp;
				}

				switch (i)
				{
					case 0:
						_fastLineSeries1.Add(myX, myY);
						break;

					case 1:
						_fastLineSeries2.Add(myX, myY);
						break;

					case 2:
						_fastLineSeries3.Add(myX, myY);
						break;

					case 3:
						_fastLineSeries4.Add(myX, myY);
						break;
				}
			}

			_tChart1.AutoRepaint = true;
			_tChart1.Invalidate();			
		}
		

	}
}
Thanks

Re: Only one curve is drawn (Direct2D)

Posted: Fri Nov 14, 2014 9:33 am
by Christopher
Hello,

Could I please ask you to try the native WPF Direct2D-enabled control, a beta of which can be downloaded from here. Does this resolve the issue?