Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
50
xamdatachart Multiple series in one chart
posted

Everyone,

I'm working on a xamdatachart that would need to chart two series (common x axis but two y axes). I'm using the following xaml code but I can't seem to figure out the background code to accomplish this.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

<

 

 

 

ig:XamDataChart Grid.Row="1" HorizontalAlignment="Stretch" Name="backtestChart" VerticalAlignment="Stretch" VerticalZoomable="True" VerticalContentAlignment="Stretch" HorizontalZoomable

="True">

 

 

 

 

<ig:XamDataChart.Axes

>

 

 

 

 

<ig:NumericYAxis x:Name

="yAxis" />

 

 

 

 

<ig:NumericYAxis x:Name

="xmYAxis">

 

 

 

 

<!--MinimumValue="100"

MaximumValue="10000">-->

 

 

 

 

<ig:NumericYAxis.LabelSettings

>

 

 

 

 

<ig:AxisLabelSettings Foreground

="#FF69177C"

 

 

 

FontSize

="12"

 

 

 

HorizontalAlignment

="Center"

 

 

 

VerticalAlignment

="Center"

 

 

 

Location

="OutsideRight"

 

 

 

Angle="{Binding ElementName=sldYAxisAngle, Path

=Value}"

 

 

 

Extent="{Binding ElementName=sldYAxisExtend, Path

=Value}" />

 

 

 

 

</ig:NumericYAxis.LabelSettings

>

 

 

 

 

</ig:NumericYAxis

>

 

 

 

 

<ig:CategoryXAxis

 

 

 

x:Name="xAxis"

 

 

 

ItemsSource="{Binding}"

 

 

 

Label

="{}{Label}"/>

 

 

 

 

</ig:XamDataChart.Axes

>

 

 

 

 

<ig:XamDataChart.Series

>

 

 

 

 

<ig:LineSeries

 

 

 

x:Name="PL"

 

 

 

ItemsSource="{Binding}"

 

 

 

XAxis="{Binding ElementName=xAxis}"

 

 

 

YAxis="{Binding ElementName=yAxis}"

 

 

 

ValueMemberPath="Value" Thickness

="2" />

 

 

 

 

<ig:LineSeries

 

 

 

x:Name="Test"

 

 

 

ItemsSource="{Binding}"

 

 

 

XAxis="{Binding ElementName=xAxis}"

 

 

 

YAxis="{Binding ElementName=yAxis}"

 

 

 

ValueMemberPath="Value" Thickness

="2" />

 

 

 

 

<ig:FinancialPriceSeries x:Name

="PriceSeries"

 

 

 

DisplayType

="Candlestick"

 

 

 

TrendLineThickness

="12"

 

 

 

TrendLineType

="ModifiedAverage"

 

 

 

ItemsSource="{Binding

}"

 

 

 

OpenMemberPath

="Open"

 

 

 

CloseMemberPath

="Close"

 

 

 

HighMemberPath

="High"

 

 

 

LowMemberPath

="Low"

 

 

 

VolumeMemberPath

="Volume"

 

 

 

XAxis="{Binding ElementName

=commonXAxis}"

 

 

 

YAxis="{Binding ElementName

=priceYAxis}">

 

 

 

 

</ig:FinancialPriceSeries

>

 

 

 

</ig:XamDataChart.Series>

So, I've got two NumericYaxes which I'm guessing would let me chart two series but I can't seem to figure out how to accomplish it. When I try to add the second series, the chart only charts the second and ignores the second series. This is the code behind:

 

 

var data = from row in backtestTable

.Rows.OfType<

 

DataRow>()

 

 

select new DataItem()

{

Label = (

 

string)row["Date"].ToString(),

Value =

 

double.Parse(row["Price"].ToString())

};

backtestChart.DataContext = data;

data =

 

from row in backtestTable

.Rows.OfType<

 

DataRow>()

 

 

select new DataItem()

{

Label = (

 

string)row["Date"].ToString(),

Value =

 

double.Parse(row["Sales"].ToString())

};

backtestChart.Series[

 

"Test"].DataContext = data;

 

I would really appreciate any help.

Thanks,

K

  • 5
    posted

    I recently discovered that all of the series sharing a category X axis must have the same number of items as the collection bound to the X axis.  Only series with a matching number of items will be rendered, even though you can see them all in the legend.

    Jon

  • 195
    posted

    Hi ,

     I would like to re iterate your issue , I  presume you are trying to plot the two LineSeries  "PL" and  "Test" with the same CategoryXAxis and seperate  NumericYAxis  for each of these.

    If my presumption is correct , I notice in your Xaml pasted above that the YAxis for both of the LineSeries is the same ; the ElementName for the YAxis for both the LineSeries is "yAxis" . You would need to bind the second line series "Test" YAxis to  "xmYAxis". I changed that in my sample and was able to plot both the LineSeries with the respective Axes. I have attached a screenshot of what i see.

    If this is not what you are looking at , can you please attach a sample application showcasing your issue ?

    Are you having  problem creating a new Series at runtime with common XAxis and seperate YAxis that are defined in the Xaml ?

    Thanks,

    Shilpa