I am having issue using ColorBand tool, the colorband tools gets really slow (sometimes stuck) while rendering if either of the colorband's edge is editable and is not in the charts viewable region. Please look at the sample code below, look at the Start value of the color band and set its value anything other than the visible reagion of the chart ( e.g change start to -999).
Please also verify if i am using the correct dll version for TeeChart.WPF.dll.( The version i am using is 4.1.2012.9287)
Thanks
Syd.
Code: Select all
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows;
using System.Windows.Media;
using Steema.TeeChart.WPF;
using Steema.TeeChart.WPF.Functions;
using Steema.TeeChart.WPF.Styles;
using Steema.TeeChart.WPF.Tools;
namespace TChartSample
{
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
DrawChart();
}
ColorBand tool;
// xAxis (x)
List<PlotValue<DateTime, double?>> xValues = new List<PlotValue<DateTime, double?>>();
// y1
List<PlotValue<DateTime, double?>> y1 = new List<PlotValue<DateTime, double?>>();
List<PlotValue<double?, double?>>[] plotValues = new List<PlotValue<double?, double?>>[2];
private void DrawChart()
{
var axis = new Axis(tc.Chart)
{
Title = new AxisTitle { Caption = "TEST", Angle = 90 },
Visible = true,
Automatic = true,
PositionUnits = PositionUnits.Pixels,
RelativePosition = 0,
TickOnLabelsOnly = false,
Labels = { Style = AxisLabelStyle.Auto },
};
// Set Chart props
tc.Axes.Bottom.Automatic = true;
tc.Axes.Bottom.Labels.DateTimeFormat = string.Empty;
tc.Axes.Bottom.Labels.ValueFormat = string.Empty;
tc.Aspect.View3D = false;
tc.Legend.Visible = false;
tc.Zoom.Allow = true;
tc.Zoom.Direction = ZoomDirections.Horizontal;
#region Series1
var pointSeries1 = new Points(tc.Chart);
pointSeries1.Title = "pxPoint1";
pointSeries1.TreatNaNAsNull = true;
pointSeries1.TreatNulls = TreatNullsStyle.DoNotPaint;
pointSeries1.Function = new DownSampling(tc.Chart) { Method = DownSamplingMethod.MinMaxFirstLastNull };
pointSeries1.Color = Colors.Tomato;
pointSeries1.Pointer.Style = PointerStyles.Rectangle;
// xAxis (x)
xValues = GetValues(DateTime.Now.Date, 1, 20);
// y1
y1 = GetValues(DateTime.Now.Date, 1, 40);
plotValues[0] = GetPlotValues(xValues, y1);
pointSeries1.Add(plotValues[0].Select(x => x.X).ToArray(), plotValues[0].Select(x => x.Y).ToArray());
pointSeries1.CheckDataSource();
pointSeries1.CustomVertAxis = axis;
#endregion
tc.Axes.Custom.Add(axis);
#region ColorBand Tool
tool = new ColorBand(tc.Chart);
tc.Tools.Add(tool);
tool.Axis = axis;
tool.ResizeEnd = true;
tool.ResizeStart = true;
// This is creating issue when either start or end is out of visible region of the chart.
tool.Start = 5;
tool.End = 20;
#endregion
}
public List<PlotValue<DateTime, double?>> GetValues(DateTime sDateTime, int randomMinValue, int randomMaxValue)
{
var random = new Random();
var values = new List<PlotValue<DateTime, double?>>();
for (int i = 0; i < 10; i++)
{
values.Add(new PlotValue<DateTime, double?> { X = sDateTime, Y = random.Next(randomMinValue, randomMaxValue) });
sDateTime = sDateTime.AddMinutes(1);
}
return values;
}
private List<PlotValue<double?, double?>> GetPlotValues(IEnumerable<PlotValue<DateTime, double?>> xValues, List<PlotValue<DateTime, double?>> yValues)
{
var plotValues = new List<PlotValue<double?, double?>>();
foreach (var xVal in xValues)
{
double? y = yValues.Find(v => v.X == xVal.X).Y;
plotValues.Add(new PlotValue<double?, double?> { X = xVal.Y, Y = y });
}
return plotValues;
}
}
public class PlotValue<T1, T2>
{
public T1 X { get; set; }
public T2 Y { get; set; }
}
}