How to show array content with a LineSeries

Aug 13, 2009 at 5:22 PM

Hello all,

I'd like to present some technical data with the charting controls.

I normally have a file with measurement data which I read into a one-dimensional array (datatype single).

Could someone show me a simple way how I can visualize the array content within a LineSeries ?

 

Thanks for any help,

Ralf.

 

Coordinator
Aug 17, 2009 at 9:27 PM

Ralf,

Please have a look at the samples that come with the Silverlight Toolkit version of Data Visualization, or have a look at the following tutorial:

http://blogs.msdn.com/delay/archive/2008/10/28/announcing-a-free-open-source-charting-solution-for-silverlight-silverlight-toolkit-released-today-at-pdc.aspx

At the end of the day, this should be as easy as setting ItemsSource = new short[] { 1, 2, 3};

Aug 19, 2009 at 11:02 AM
Thanks for your answer, David.

I'm sorry, but I've got further problems.
Especially with displaying an array in a LineSeries.

I'm surely missing something trivial, but maybe someone could give me a hint.

First I tried the easiest sample with the ColumnSeries:

XAML:
<Grid>
<chartingToolkit:Chart Title="1stLine">
<chartingToolkit:ColumnSeries Title="Spannung" Name="ColumnSeries1">

</chartingToolkit:ColumnSeries>
</chartingToolkit:Chart>
</Grid>

Code:
ColumnSeries1.ItemsSource = new short[] {1,2,3}; (directly after InitializeComponent())

Works perfect.

Tried exactly the same just replaced all ColumnSeries with LineSeries.

There I get an ArgumentNullExecption for Parameter category' in in the function DataPointSeries.Refresh().

So I added a DependentRangeAxis:
<Grid>
<chartingToolkit:Chart Title="1st Line">
<chartingToolkit:LineSeries Title="Voltage" Name="LineSeries1">
<chartingToolkit:LineSeries.DependentRangeAxis>
<chartingToolkit:LinearAxis
Orientation="Y"
Title="Measure"
Minimum="0"
Maximum="3"
Interval="1"
ShowGridLines="True">
</chartingToolkit:LinearAxis>
</chartingToolkit:LineSeries.DependentRangeAxis>
</chartingToolkit:LineSeries>
</chartingToolkit:Chart>
</Grid>

Code:
LineSeries1.ItemsSource = new short[] { 1,2,3};

Again an ArgumentNullExection for Parameter category now in the function CategoryAxis.GetPlotAreaCoordinateRange().

What am I missing ?
Is it really possible to put an 1D-array into the LineSeries like into the ColumnSeries ?

PS:
Tried to add a horizontal axis
<chartingToolkit:Chart.Axes>
<chartingToolkit:LinearAxis
Orientation="X" ....
When compiling I get the error 'Could not create an instance of type 'LinearAxis'.
So I can't try more in that direction at the moment.


Thanks again,
Ralf.
______________________________________________________
GRATIS für alle WEB.DE-Nutzer: Die maxdome Movie-FLAT!
Jetzt freischalten unter http://movieflat.web.de
Coordinator
Aug 19, 2009 at 7:07 PM

ColumnSeries can infer its DependentValueBinding and IndependentValueBinding is optional. For LineSeries, it's not. So you'll need to add something like IndependentValueBinding="{Binding }" to your LineSeries definition to see this simple example work. FYI, you can play around with this stuff interactively with my ChartBuilder sample: http://cesso.org/Samples/ChartBuilder/.

PS - Eventually, you'll probably want to move from an array of shorts to an array of objects that has distinct X and Y properties so you'll have better control of how things chart.

Aug 20, 2009 at 4:30 PM
Thanks for your help.
I managed two things thus far.
With your help I put a 1D-array into a LineSeries. This works, but I have no X-axis so that same values are at the same point (like in ChartBuilder)
Second I created a collection of objects (with x and y properties) following the ChartigIntroduction. This worked fine for a little amount of values.
But if I try to chart about 40.000 elements, the charting application takes a huge amount of memory, has 100% cpu usage
and shows even after 10 minutes nothing (on a 1 GB RAM machine).
Read 40.000 UInt32 values out of a file into dwArrayValues:
int i = 1;
//- Array to LineSeries
foreach (UInt32 dwIndex in dwArrayValues)
{
DataCollection.Add(new VoltageData(i,(int)dwIndex));
i++;
}
LineSeries1.ItemsSource = DataCollection;

public class VoltageData
{
public int Voltage { get; set; }
public int Sample { get; set; }
public VoltageData(int kSample, int kVoltage)
{
Voltage = kVoltage;
Sample = kSample;
}
}
public class VoltageDataCollection : Collection<VoltageData>
The same performance problem exists if I just put the 1D-array to LineSeries.ItemsSource.
Am I missing some important point that someone can tell me ?
What am I doing wrong and how can I increase performance ?
Kind regards,
Ralf.

Von: davidans [mailto:notifications@codeplex.com]
Gesendet: Mittwoch, 19. August 2009 20:07
An: Erdmann, Ralf
Betreff: Re: How to show array content with a LineSeries [wpf:65489]

From: davidans

ColumnSeries can infer its DependentValueBinding and IndependentValueBinding is optional. For LineSeries, it's not. So you'll need to add something like IndependentValueBinding="{Binding }" to your LineSeries definition to see this simple example work. FYI, you can play around with this stuff interactively with my ChartBuilder sample: http://cesso.org/Samples/ChartBuilder/.

PS - Eventually, you'll probably want to move from an array of shorts to an array of objects that has distinct X and Y properties so you'll have better control of how things chart.