Hi,
I would like to know how to use the Strip line in the XamDataChart. I would like to add different colour bands on the chart according to the data in the chart? Can anyone please advise me on this function?
Thanks,
Pieter
Pieter, you can set a brush on the Strip property on both axes. You should pick a color with some transparency (change the alpha value) and you will see a neat effect on the strip crossing. But are you talking about putting the strip at a configurable set of values? We don't directly support this, but I may be able to help you out with a sample. Could you explain in more detail what you are trying to do?
-Graham
Hi Graham,
Thanks again for replying.
I am adding an image this is just an example of what I should do. There is a trace on the graph if it drops below 0 it should make the background red, if it stays on a point for longer than 10 minutes the background must be orange and the last one if it goes above 20 it must change the background to green. My problem is I don’t know how to do this checks in XAML and I don’t know what function to call in C#?
I will appreciate any advice on this. The XAML code is the same as my other post on the X Axis.
Thank You!
Pieter,
Make sure you have "using System.Linq;" with your other using statements at the top of the file. Let me know if that resolves the problem.
I do have the System.Linq in. I did some googeling but I can’t get an answer.
Thank You,
This is everything I have in.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Infragistics.Controls.Charts;
using Infragistics.Collections;
using System.Data.Linq;
using System.Collections.ObjectModel;
using System.Collections.Specialized;
Wrote that sample against Silverlight and the types look a bit different in WPF, if you replace:
xAxis.RootCanvas.Children with xAxis.RootCanvas.Children.OfType<UIElement>()
you should be ok.
Let me know if that helps.
It works perfect! Thank you so much!!
Will it be possible to add new strips in the code behind, I did try something but it's not working. Don't know if it's possible.
StripLines.StripInfo SI = new StripLines.StripInfo();
//StripInfo SI = new StripInfo();
SI.StartX = 3;
SI.EndX = 4;
SI.Label = "Test";
Brush br = Brushes.Blue;
SI.Fill = br;
I am new to WPF and did not touch Silverlight jet so all this is still new to me.
Thanks for all the help!
If you've defined the ChartStripsBehavior in the xaml, then you can programmatically add strips like this:
StripInfo si = new StripInfo(); si.StartX = 1; si.EndX = 2; si.Fill = new SolidColorBrush(Colors.Green); ChartBehaviors.GetChartStrips(theChart).Strips.Add(si);
If you haven't then you can set up the ChartStripsBehavior in the code behind and then call
ChartBehaviors.SetChartStrips(theChart, stripsBehavior);
Let me know if you have any questions. The above is what's known as an Attached Property in Silverlight/WPF.
Aha. I was using a CategoryXAxis when I should have been using a CategoryDateTimeXAxis with the DateTime MemberPath set.
My strips are not drawing. Do you have any idea why the GetScaledValue function would return numbers like 1.1378021398827587E+18 for a date of 11/1/2011 1:00:00 AM (634557060000000000 Ticks), a window {0,0,1,1}, and a viewport {0,0,467.99,277.04}? That's the end date. The start date is 7/20/2011 1:00:00 AM (634467204000000000 Ticks) scales to 1.137641022222069E+18. I don't think this function is behaving correctly. Do you happen to have a scaling function that works correctly?
An approach like above presented needs to be more complicated in order to deal with that kind of volume. Is there a sample that you can provide that replicates your scenario? I may be able to point out how you can adjust this extension in order to perform well with that level of annotation. But, as a warning, the code is likely to be more complicated.
Performance is absolutely horrendeous on these strips. I have a chart with 2000 points and 200 annotations like this.
For anyone else interested, Graham's solution relies on XamDataChart events firing to refresh strips which you may need to address when the chart is set as the XamZoombar preview content.
Additionally the GetScaledValue calls rely on x axis ActualMinimumValue and ActualMaximumValue having meaningful values, which in my situation was not the case. This is easily overcome by implementing your own scaling method.