Reputation: 33
I have a UWP app to control a kiln.I represent the temperature of the kiln over time in a Linegraph from the WinRT XAML Toolkit. To display I use this XAML:
<Charting:Chart x:Name="MyLineSeriesChart" Grid.ColumnSpan="4" VerticalAlignment="Center" FontSize="10" HorizontalContentAlignment="Left" RenderTransformOrigin="-0.082,0.454" Width="480" Height="250" HorizontalAlignment="Left">
<Charting:Chart.Axes >
<Charting:DateTimeAxis AxisLabelStyle="{StaticResource HorizontalLabelStyle}" Orientation="X"/>
</Charting:Chart.Axes>
<Charting:LineSeries Name="LineChart" Title="Temp" ItemsSource="{Binding}" DependentValueBinding="{Binding Path=Value}" IndependentValueBinding="{Binding Path=Key}" Margin="0,-38,-75,0" HorizontalAlignment="Stretch" Width="Auto">
<!-- <Charting:LineSeries.DependentRangeAxis>
<Charting:LinearAxis Orientation="Y" ShowGridLines="True" Title="Temp"/>
</Charting:LineSeries.DependentRangeAxis>-->
<Charting:LineSeries.DataPointStyle>
<Style TargetType="Charting:LineDataPoint">
<Setter Property="Visibility" Value="Collapsed"/>
<Setter Property="Width" Value="0"/>
<Setter Property="Background" Value="Red"/>
</Style>
</Charting:LineSeries.DataPointStyle>
</Charting:LineSeries>
</Charting:Chart>
You see a commented out part. I used that before. It worked OK but I wanted a different interval. In XAML you cannot set an interval because of the not nullable problem. So I set the interval in VB code:
DirectCast(MyLineSeriesChart.Series(0), LineSeries).DependentRangeAxis = New LinearAxis() With {
.Title = "Temp",
.Orientation = AxisOrientation.Y,
.Minimum = 0,
.Maximum = 1000,
.Interval = 100,
.ShowGridLines = True
}
But the result is worse:
The temperature starts at 15 C up to about 1.000 C. But as you can see the graph shows very different figures. The actual temps in the graph's time were 15 to 200 C.
I pull my hair out as to why?
Upvotes: 0
Views: 349
Reputation: 31
Somewhat of an old post, I realize, but wanted to briefly provide some information in case someone runs into this too and is having the same issues. I had the same problem as described above (values were not were they were 'meant' to be on the Y-axis) but upon stepping through the code, I found that the margin property (set in the above code to Margin="0,-38,-75,0") was causing the shift. Setting it to Margin="0,0,-75,0" resolved the issue for me... the -75 value is somewhat arbitrary based on what data is being shown.
Upvotes: 0
Reputation: 13
I just test your XAML code snippet, my graph was also not placed properly. So, I just removed following from the code and its just perfect
<Setter Property="Visibility" Value="Collapsed"/>
<Setter Property="Width" Value="0"/>
Hope it will help you.
Thanks
Upvotes: 0