Is there a way to combine one column series & one scatter series in the same XamChart (V2011.2)?
Thanks!
Thanks for your help. it's working!
Hello Lilys,
I am just checking if you require any further assistance on the matter.
Sincerely,
Krasimir
Developer Support Engineer
Infragistics
www.infragistics.com/support
I have been looking into the functionality that you are looking for and I have modified the sample application that I have sent to you earlier in order to follow the functionality that Graham Murray has implemented in the following forum post: http://forums.infragistics.com/forums/p/51914/291335.aspx#291335 . I have changed the ColorPath to the Threshold property that you have added to the Data class. I have modified the UpdateColor method in order to set a Color property of the RectangleColorChanger class, to a MultiBinding object and added two Binding objects to its Bindings collection. Both binding have as source the data item that corresponds to the rectangle and for Path I have set the ColorPath for the first binding and the ValueMemberPath for the second one. In the converter for the MultiBinding I am comparing the two integer values (form Threshold property and the property corresponding to the ValueMemberPath) and returning the appropriate color.
If you have any further questions on the matter please do not hesitate to ask
I added public int Threshold to your Data class.
If value > Threshhld, i need to display Column Green.
Else i need to display column red.
See the code below:
---xaml file------
<
Window x:Class="ScatterAndColumn.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:ScatterAndColumn"
Title="MainWindow" Height="350" Width="525" xmlns:ig="http://schemas.infragistics.com/xaml">
<Grid>
<ig:XamDataChart
Name="xamDataChart1">
<ig:XamDataChart.Resources>
<Style TargetType="Rectangle">
<Setter Property="local:StyleBinder.StyleBinderHelper">
<Setter.Value>
<local:StyleBinderHelper>
<local:StyleBinderHelper.Template>
<DataTemplate>
<local:RectangleColorChanger
YAxis="{Binding OuterContext.Series.YAxis}"
Value="{Binding Owner.ActualHeight}"
Threshold="{Binding Owner.Threshold}"
Rectangle="{Binding Owner}" />
</DataTemplate>
</local:StyleBinderHelper.Template>
</local:StyleBinderHelper>
</Setter.Value>
</Setter>
</Style>
</ig:XamDataChart.Resources>
<ig:XamDataChart.Axes>
<ig:NumericXAxis
x:Name="ScatterXAxis" />
<ig:NumericYAxis
x:Name="ScatterYAxis" />
<ig:CategoryXAxis
x:Name="CatXAXis"
ItemsSource="{Binding}"/>
</ig:XamDataChart.Axes>
<ig:XamDataChart.Series>
<ig:ColumnSeries
ItemsSource="{Binding}"
XAxis="{Binding ElementName=CatXAXis}"
YAxis="{Binding ElementName=ScatterYAxis}"
Tag="{Binding Path=Threshold}"
ValueMemberPath="Value"/>
<ig:ScatterSeries
XAxis="{Binding ElementName=ScatterXAxis}"
MarkerType="Diamond" MarkerBrush="Black"
XMemberPath="Open"
YMemberPath="Close"/>
</ig:XamDataChart.Series>
</ig:XamDataChart>
</Grid>
</
Window>
---code behind----------
using
System;
System.Collections.Generic;
System.Linq;
System.Text;
System.Windows;
System.Windows.Controls;
System.Windows.Data;
System.Windows.Documents;
System.Windows.Input;
System.Windows.Media;
System.Windows.Media.Imaging;
System.Windows.Navigation;
System.Windows.Shapes;
System.ComponentModel;
System.Collections.ObjectModel;
namespace
ScatterAndColumn
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
public MainWindow()
InitializeComponent();
DataContext =
Data.GetData(10, 10, 100);
}
public class Data : INotifyPropertyChanged
private int open;
private int close;
private int high;
private int low;
private int value;
private string label;
private int threshold = 1;
public int Threshold
get { return Close; }
set
threshold =
value;
PropChanged(
"Threshold");
public string Label
get { return label; }
label =
"Label");
public int Open
get { return open; }
open =
"Open");
public int Close
get { return close; }
close =
"Close");
public int High
get { return high; }
high =
"High");
public int Low
get { return low; }
low =
"Low");
public int Value
get { return value; }
this.value = value;
"Value");
public static ObservableCollection<Data> GetData(int points, int rangeStart, int rangeEnd)
ObservableCollection<Data> data = new ObservableCollection<Data>();
Random r = new Random();
for (int i = 0; i < points; i++)
data.Add(
new Data
Label = i.ToString(),
Open = i,
//r.Next(rangeStart, rangeEnd),
Close = r.Next(rangeStart, rangeEnd),
High = r.Next(rangeStart, rangeEnd),
Low = r.Next(rangeStart, rangeEnd),
Value = r.Next(rangeStart, rangeEnd),
});
return data;
public event PropertyChangedEventHandler PropertyChanged;
public void PropChanged(string name)
if (PropertyChanged != null)
PropertyChanged(
this, new PropertyChangedEventArgs(name));
Infragistics.Controls.Charts;
public static class StyleBinder
public static readonly DependencyProperty StyleBinderHelperProperty =
DependencyProperty.RegisterAttached(
"StyleBinderHelper",
typeof(StyleBinderHelper),
typeof(StyleBinder),
new PropertyMetadata(null,
(o, e) => StyleBinderHelperChanged(o, e)));
private static void StyleBinderHelperChanged(
DependencyObject o,
DependencyPropertyChangedEventArgs e)
FrameworkElement ele = o as FrameworkElement;
if (ele == null)
return;
BindingExpression be =
ele.GetBindingExpression
(
StyleBinder.StyleBinderContextProperty);
if (be == null)
ele.SetBinding(StyleBinderContextProperty,
new Binding());
if (e.NewValue != null)
((
StyleBinderHelper)e.NewValue).PushContent(ele);
public static void SetStyleBinderHelper(
DependencyObject target,
StyleBinderHelper value)
target.SetValue(StyleBinderHelperProperty, value);
public static StyleBinderHelper GetStyleBinderHelper(
DependencyObject target)
return (StyleBinderHelper)target.GetValue(StyleBinderHelperProperty);
public static readonly DependencyProperty StyleBinderContentProperty =
"StyleBinderContent",
typeof(FrameworkElement),
(o, e) => StyleBinderContentChanged(o, e)));
private static void StyleBinderContentChanged(
public static void SetStyleBinderContent(
FrameworkElement value)
target.SetValue(StyleBinderContentProperty, value);
public static FrameworkElement GetStyleBinderContent(
return (FrameworkElement)target.GetValue(StyleBinderContentProperty);
public static readonly DependencyProperty StyleBinderContextProperty =
"StyleBinderContext",
typeof(object),
(o, e) => StyleBinderContextChanged(o, e)));
private static void StyleBinderContextChanged(
FrameworkElement content =
StyleBinder.GetStyleBinderContent(o);
if (content != null)
content.DataContext =
new HelperContext()
OuterContext = e.NewValue,
Owner = o
as FrameworkElement
};
public static void SetStyleBinderContext(
object value)
target.SetValue(StyleBinderContextProperty, value);
public static object GetStyleBinderContext(
return target.GetValue(StyleBinderContextProperty);
public class StyleBinderHelper
:
FrameworkElement
internal void PushContent(FrameworkElement ele)
if (Template == null)
FrameworkElement content = Template.LoadContent() as FrameworkElement;
if (content == null)
OuterContext =
StyleBinder.GetStyleBinderContext(ele),
Owner = ele
StyleBinder.SetStyleBinderContent(ele, content);
public DataTemplate Template { get; set; }
public class HelperContext
INotifyPropertyChanged
private object _outerContext;
public object OuterContext
get { return _outerContext; }
_outerContext =
RaisePropertyChanged(
"OuterContext");
private FrameworkElement _owner;
public FrameworkElement Owner
get { return _owner; }
_owner =
"Owner");
private void RaisePropertyChanged(string propertyName)
this,
new PropertyChangedEventArgs(propertyName));
public class RectangleColorChanger
public static readonly DependencyProperty ValueProperty =
DependencyProperty.Register(
"Value",
typeof(double),
typeof(RectangleColorChanger),
new PropertyMetadata(0.0, (o, e) => (o as RectangleColorChanger)
.ValueChanged(e)));
public double Value
get { return (double)GetValue(ValueProperty); }
set { SetValue(ValueProperty, value); }
public static readonly DependencyProperty ThresholdProperty =
"Threshold",
.ThresholdChanged(e)));
private void ThresholdChanged(
UpdateColor();
public double Threshold
get { return (double)GetValue(ThresholdProperty); }
set { SetValue(ThresholdProperty, value); }
public static readonly DependencyProperty RectangleProperty =
"Rectangle",
typeof(Rectangle),
(o, e) => (o
as RectangleColorChanger)
.RectangleChanged(e)));
private void UpdateColor()
if (YAxis == null)
if (Rectangle == null)
Rect viewport = new Rect(0, 0, YAxis.ActualWidth, YAxis.ActualHeight);
double zero = YAxis.GetScaledValue(YAxis.ReferenceValue, YAxis.Chart.WindowRect, viewport);
double top = Rectangle.TransformToVisual(YAxis).Transform(new Point(0, 0)).Y;
double bottom = Rectangle.TransformToVisual(YAxis).Transform(new Point(0, Rectangle.Height)).Y;
double val = 0;
if (top < zero && bottom <= zero)
val = YAxis.GetUnscaledValue(top, YAxis.Chart.WindowRect, viewport);
else
val = YAxis.GetUnscaledValue(bottom, YAxis.Chart.WindowRect, viewport);
if (val < Threshold)
Rectangle.Fill =
new SolidColorBrush(Colors.Red);
new SolidColorBrush(Colors.Green);
private void RectangleChanged(DependencyPropertyChangedEventArgs e)
public Rectangle Rectangle
get { return (Rectangle)GetValue(RectangleProperty); }
set { SetValue(RectangleProperty, value); }
private void ValueChanged(DependencyPropertyChangedEventArgs e)
public static readonly DependencyProperty YAxisProperty =
"YAxis",
typeof(NumericYAxis),
new PropertyMetadata(null, (o, e) => (o as RectangleColorChanger)
.YAxisChanged(e)));
private void YAxisChanged(
public NumericYAxis YAxis
get { return (NumericYAxis)GetValue(YAxisProperty); }
set { SetValue(YAxisProperty, value); }
I have been reading through your post and when you use a XamChart you can use the ScatterSeries with a ScatterLine. If you wish to display column and scatter series at the same chart, I can suggest using the XamDataChart. The XamDataChart allows you to combine the two types of series. I have created a sample application for you which demonstrates how you can use the XamDataCahrt, in order to achieve the functionality that you are looking for.
If you have any further questions please do not hesitate to ask.