Silverlight Toolkit chart: Multiple series with bar and line - silverlight

I am having problem to show the grid in a way that I wanted. But I am also not sure whether it is possible to do that in the Silverlight toolkit chart. So any help or direction on this would be appreciated.
<Grid x:Name="LayoutRoot" Background="White">
<charting:Chart x:Name="myChart" Width="600" Height="400">
<charting:BarSeries
Title="Tasks"
ItemsSource="{Binding Path=Data1}"
IndependentValueBinding="{Binding Month}"
DependentValueBinding="{Binding Task}"
DependentRangeAxis="{Binding ElementName=TaskAxis}">
</charting:BarSeries>
<charting:LineSeries
Title="Benefits"
ItemsSource="{Binding Path=Data1}"
IndependentValueBinding="{Binding Month}"
DependentValueBinding="{Binding Benefits}"
DependentRangeAxis="{Binding ElementName=BenefitsAxis}">
</charting:LineSeries>
<charting:Chart.Axes>
<charting:LinearAxis Orientation="Y" Location="Left" Title="First" x:Name="TaskAxis" />
<charting:LinearAxis Orientation="Y" Location="Right" Title="Second" x:Name="BenefitsAxis" />
</charting:Chart.Axes>
</charting:Chart>
</Grid>
Given the above snippet, is it possible to have the Yaxis on the left to show the month and the top x-axis to show the tasks value, and bottom x-axis to show the benefits value.
So in a way, it is sharing the Yaxis for the month. and it can use either top/bottom x-axis or even right Yaxis to plot the tasks and benefits value.
What do you guys think?
Thanks.

The example below has the task axis on the top and the benefits axis on the bottom, with a shared Y-axis on the left:
<toolkit:Chart x:Name="myChart" Width="600" Height="800">
<toolkit:BarSeries
Title="Tasks"
ItemsSource="{Binding Path=Data1}"
IndependentValueBinding="{Binding Month}"
DependentValueBinding="{Binding Task}"
DependentRangeAxis="{Binding ElementName=TaskAxis}">
</toolkit:BarSeries>
<toolkit:BarSeries
Title="Benefits"
ItemsSource="{Binding Path=Data1}"
IndependentValueBinding="{Binding Month}"
DependentValueBinding="{Binding Benefits}"
DependentRangeAxis="{Binding ElementName=BenefitsAxis}">
</toolkit:BarSeries>
<toolkit:Chart.Axes>
<toolkit:LinearAxis Orientation="X" Location="Top" Title="Task" x:Name="TaskAxis" />
<toolkit:LinearAxis Orientation="X" Location="Bottom" Title="Benefits" x:Name="BenefitsAxis" />
</toolkit:Chart.Axes>
</toolkit:Chart>

Related

How to change the stringformat of Oxyplot track value?

If I change the stringformat of axis, it works for the axis (see the black circle of the picture). But how can I change the stringformat of the track value (the red circle)?
I'd like to answer my own question based on Ramin's hint to me.
I dug into the source code a little bit, and found out there is a TrackerFormatString that I can change:
<oxy:LineSeries TrackerFormatString="{}{0}
{1}: {2:0.0}
{3}: {4:0.0}"/>
Please note the
in my code, that how a newline char is input in XAML.
Please also note the {} in the very beginning, that's kind of escape char in XAML.
if in c#, it's just:
{0}\n{1}: {2:0.0}\n{3}: {4:0.0}
You should set DefaultTrackerTemplate. Here a small example that shows you the way:
<Grid>
<oxy:Plot Title="AAA">
<oxy:Plot.Axes>
<oxy:LinearAxis Position="Left" Title="Left: " />
<oxy:LinearAxis Position="Bottom" Title="Bottom: " />
</oxy:Plot.Axes>
<oxy:Plot.Series>
<oxy:LineSeries x:Name="ls" ItemsSource="{Binding Points}"/>
</oxy:Plot.Series>
<oxy:Plot.DefaultTrackerTemplate>
<ControlTemplate>
<oxy:TrackerControl Position="{Binding Position}"
BorderThickness="1">
<oxy:TrackerControl.Content>
<StackPanel >
<DockPanel>
<TextBlock Text="{Binding XAxis.Title}" Foreground="Red" />
<TextBlock DockPanel.Dock="Right" Text="{Binding DataPoint.X}" Foreground="Red" />
</DockPanel>
<DockPanel>
<TextBlock Text="{Binding YAxis.Title}" Foreground="Green" />
<TextBlock DockPanel.Dock="Right" Text="{Binding DataPoint.Y}" Foreground="Green"
FontWeight="Bold" />
</DockPanel>
</StackPanel>
</oxy:TrackerControl.Content>
</oxy:TrackerControl>
</ControlTemplate>
</oxy:Plot.DefaultTrackerTemplate>
</oxy:Plot>
</Grid>
Hope it helps.

WPF DVC Chart axis labeling

I have created a DVC:Chart as shown below in my code, how do i add x-axis and y-axis labels to the chart?
<DVC:Chart Name="callLogs"
Background="SteelBlue" Grid.ColumnSpan="2">
<DVC:Chart.Series>
<DVC:ColumnSeries Title="Calls per Hour"
IndependentValueBinding="{Binding Path=Key}"
DependentValueBinding="{Binding Path=Value}">
</DVC:ColumnSeries>
</DVC:Chart.Series>
</DVC:Chart>
Thanks in advance
I have managed to figure it out:
<DVC:Chart Name="callLogs"
Background="SteelBlue" Grid.ColumnSpan="2">
<DVC:Chart.Axes>
<DVC:LinearAxis Orientation="Y" Title="Ammount of calls"/>
<DVC:LinearAxis Orientation="X" Title="Time (Hours)"/>
</DVC:Chart.Axes>
<DVC:Chart.Series>
<DVC:ColumnSeries Title="Calls per Hour"
IndependentValueBinding="{Binding Path=Key}"
DependentValueBinding="{Binding Path=Value}">
</DVC:ColumnSeries>
</DVC:Chart.Series>
</DVC:Chart>
However, its labeling my x-axis for me, don't know how to customize it, so i will post the new solution when i figure it out.

How can you set the horizontal axis interval in a WPF Toolkit Chart Control?

I'm using the chart control from the WPF Toolkit. How can I set the interval of the X axis?
I have the following XAML code:
<Grid Height="800">
<chartingToolkit:Chart Name="lineChart" Title="Pressure over Time"
VerticalAlignment="Top" Margin="20,50,20,0" Height="500">
<chartingToolkit:Chart.Axes>
<chartingToolkit:LinearAxis Title="Pressure" Orientation="Y" Interval="100" />
<chartingToolkit:LinearAxis Title="Time" Orientation="X" Interval="100" />
</chartingToolkit:Chart.Axes>
<chartingToolkit:LineSeries DependentValuePath="Value" IndependentValuePath="Key" ItemsSource="{Binding}" Name="Test"
IsSelectionEnabled="True" ClipToBounds="False">
</chartingToolkit:LineSeries>
</chartingToolkit:Chart>
<Button Width="100" Height="24" Margin="20,556,1058,220" Content="More" Name="Button1" />
</Grid>
The Y Axis works fine, it shows the interval of 100 but the X axis puts itself on the top (please see the added image) and the interval is the exact amounts of points. Why doesnt it listen to the Interval="100" property in the xaml? And why doesn't it place itself on the bottom?
For the location of the linearAxis, you can set the Location property to "Bottom"
in code:
<chartingToolkit:LinearAxis Title="Time" Orientation="X" Interval="100"
Location="Bottom" />
For the interval problem, i don't know...

Silverlight ToolKit Chart: Hide xaxis labels

Basically I have a chart with multiple bar series. The independent value for all the series are the same. So the chart's xaxes are rendered with stacked of same independent values.
If I want to make all series (except for the first one) xaxes' labels to not visible, how can i do that in the xaml declaration?
Can anyone please give me assistance on this?
Update:
I have come across example with the following code:
<toolkit:Chart x:Name="myChart" Width="600" Height="400">
<toolkit:LineSeries
Title="Tasks"
ItemsSource="{Binding}"
IndependentValueBinding="{Binding Month}"
DependentValueBinding="{Binding Task}">
</toolkit:LineSeries>
<toolkit:LineSeries
Title="Benefits"
ItemsSource="{Binding}"
IndependentValueBinding="{Binding Month}"
DependentValueBinding="{Binding Benefits}">
</toolkit:LineSeries>
<toolkit:Chart.Axes>
<toolkit:LinearAxis Orientation="Y" Location="Left" Title="First" />
<toolkit:LinearAxis Orientation="Y" Location="Right" Title="Second" />
</toolkit:Chart.Axes>
</toolkit:Chart>
If you plot the above code, you will see that both series will base the Y values from the left one. How can we change it so that first series will be plotted against Y values on the left and second series to be plotted against Y values on the right.
is that possible?
Thanks.
I think you can achieve what you want using the DependentRangeAxis properties of the LineSeries objects.
First, give each Y-axis an x:Name, for example TaskAxis and BenefitsAxis.
Then, you can tell a LineSeries to use an axis by adding to it the property
DependentRangeAxis="{Binding ElementName=TaskAxis}"
or
DependentRangeAxis="{Binding ElementName=BenefitsAxis}"
as appropriate.
The full XAML of the chart then becomes
<toolkit:Chart x:Name="myChart" Width="600" Height="400">
<toolkit:LineSeries
Title="Tasks"
ItemsSource="{Binding Path=Data1}"
IndependentValueBinding="{Binding Month}"
DependentValueBinding="{Binding Task}"
DependentRangeAxis="{Binding ElementName=TaskAxis}">
</toolkit:LineSeries>
<toolkit:LineSeries
Title="Benefits"
ItemsSource="{Binding Path=Data1}"
IndependentValueBinding="{Binding Month}"
DependentValueBinding="{Binding Benefits}"
DependentRangeAxis="{Binding ElementName=BenefitsAxis}">
</toolkit:LineSeries>
<toolkit:Chart.Axes>
<toolkit:LinearAxis Orientation="Y" Location="Left" Title="First" x:Name="TaskAxis" />
<toolkit:LinearAxis Orientation="Y" Location="Right" Title="Second" x:Name="BenefitsAxis" />
</toolkit:Chart.Axes>
</toolkit:Chart>
Another approach is to move the Axis objects inside the LineSeries. A demonstration of how to do this can be found here.

WPF Chart binding error

i have problem to correctly bind data to WPF Chart. When i'm setting ItemsSource i get error:
Assigned dependent axis cannot be used. The data may not be able to be rendered on the provided axis or the series may require that they axis has an origin.
oc = new ObservableCollection<Pair>();
heartBeats.ItemsSource = oc;
to Pair i'm saving int and long
XAML:
...
xmlns:charting="clr-namespace:System.Windows.Controls.DataVisualization.Charting;assembly=System.Windows.Controls.DataVisualization.Toolkit" >
<charting:Chart x:Name="ApplicatioChart">
<charting:Chart.Series>
<charting:ColumnSeries x:Name="heartBeats" Title="Working Set"
DependentValueBinding="{Binding First}" IndependentValueBinding="{Binding Second}" >
<charting:ColumnSeries.IndependentAxis>
<charting:CategoryAxis Orientation="X" />
</charting:ColumnSeries.IndependentAxis>
<charting:ColumnSeries.DependentRangeAxis>
<charting:LinearAxis Orientation="Y" />
</charting:ColumnSeries.DependentRangeAxis>
</charting:ColumnSeries>
</charting:Chart.Series>
</charting:Chart>
Please help.. :(
i resolved it this way:
<charting:Chart Title="Engine Performance" x:Name="ApplicationChart">
<!-- Power curve -->
<charting:LineSeries x:Name="heartBeats"
Title="ManagedHeapSize"
IndependentValueBinding="{Binding EventTime}"
DependentValueBinding="{Binding ManagedHeapSize}">
<!-- Vertical axis -->
<charting:LineSeries.DependentRangeAxis>
<charting:LinearAxis
Orientation="Y"
Title="ManagedHeapSize"
Interval="10000000" Focusable="True"
ShowGridLines="True"/>
</charting:LineSeries.DependentRangeAxis>
</charting:LineSeries>
<charting:Chart.Axes>
<!-- Shared horizontal axis -->
<charting:LinearAxis
Orientation="X"
Title="EventTime"
Interval="100"
ShowGridLines="True"/>
</charting:Chart.Axes>
</charting:Chart>
Can't see anything wrong with the mark up (apart from the same Property being bound as both the dependent and independent value).
It seems to work fine in the Silverlight version, I don't have the WPF version to play with.
Try removing the definition for the DependentRangeAxis, to see whether it works with the default one.

Resources