In multiple Y axis graph, the axis shift issue in wpf - wpf

I have chart control,depends upon the selection i have to plot a graph,here is screen shot
First case i have selected, 2 inputs and second case given 1 input. as above images it shifts axis.If i refresh it will be the proper position.
<chartingToolkit:Chart Name="lineChart" BorderThickness="0" Padding="0"
Grid.IsSharedSizeScope="True" HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch">
<chartingToolkit:Chart.LegendStyle>
<Style TargetType="Control">
<Setter Property="Template" Value="{x:Null}"/>
</Style>
</chartingToolkit:Chart.LegendStyle>
<chartingToolkit:Chart.Axes>
<chartingToolkit:LinearAxis Orientation="X" Minimum="0" Maximum="{Binding MaxX}" Title="Time (Minutes)" />
</chartingToolkit:Chart.Axes>
<chartingToolkit:LineSeries Title="Oxygen" DependentValuePath="Value" IndependentValuePath="Key" Visibility="{Binding O2.GraphVisibility}"
ItemsSource="{Binding O2.TGraph,UpdateSourceTrigger=PropertyChanged}" IsSelectionEnabled="True" HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch" Padding="0" >
<chartingToolkit:LineSeries.DataPointStyle>
<Style TargetType="chartingToolkit:LineDataPoint">
<Setter Property="Template" Value="{x:Null}" />
<Setter Property="Background" Value="{StaticResource graphO2}"/>
</Style>
</chartingToolkit:LineSeries.DataPointStyle>
<chartingToolkit:LineSeries.DependentRangeAxis>
<chartingToolkit:LinearAxis Title="{Binding O2.YTitle}" Foreground="{StaticResource graphO2}" Visibility="{Binding O2.YVisibility}" Maximum="{Binding O2.MaxY}" Orientation="Y" Location="{Binding O2.YLocation}" />
</chartingToolkit:LineSeries.DependentRangeAxis>
</chartingToolkit:LineSeries>
</chartingToolkit:Chart>
Using WPF Toolkit Data Visualization for graph.Please help me solve this issue.Coding side using MVVM architecuture.

It seems that chart doesn't refreshe in proper way, when you change input or modify dependency properties.
At least in LightningChart Visualization component, you can disable chart rendering - modify properties - continue rendering. You can easily prevent such bugs.
Try that and see the result. It has free demoapp with examples and available code. Can help you.

Related

DataVisualization.Charting.Chart Can't overlay lineseries on columnseries

I'm using the WPFToolkit v 3.5.4 to overlay two line series on a column series, but the line series are 'pushed' to the left of the column series as seen in the top graph of the image. All series are of List<KeyValuePair<double, int>> and I've checked the key/value pairs are what I want displayed.
The second graph successfully overlays three LineSeries (using different data) but looks poorly.
Is there a way to mix charting series types (ColumnSeries, LineSeries) on the same chart?
Thanks
Here's the Xaml for the two graphs in the image:
<chartingToolkit:Chart Name="lineChart1" Title="Series1" VerticalAlignment="Top" Margin="449,39,43,0" Height="262">
<chartingToolkit:ColumnSeries DependentValuePath="Value" IndependentValuePath="Key" ItemsSource="{Binding [0]}"
IsSelectionEnabled="True" />
<chartingToolkit:LineSeries DependentValuePath="Value" IndependentValuePath="Key" ItemsSource="{Binding [1]}"
IsSelectionEnabled="True" />
<chartingToolkit:LineSeries DependentValuePath="Value" IndependentValuePath="Key" ItemsSource="{Binding [2]}"
IsSelectionEnabled="True" />
<!-- Remove the legend -->
<chartingToolkit:Chart.LegendStyle>
<Style TargetType="Control">
<Setter Property="Width" Value="0"/>
<Setter Property="Height" Value="0"/>
</Style>
</chartingToolkit:Chart.LegendStyle>
</chartingToolkit:Chart>
<chartingToolkit:Chart Name="lineChart2" Title="Series2" VerticalAlignment="Top" Margin="33,330,440,0" Height="262">
<chartingToolkit:LineSeries DependentValuePath="Value" IndependentValuePath="Key" ItemsSource="{Binding [0]}"
IsSelectionEnabled="True" />
<chartingToolkit:LineSeries DependentValuePath="Value" IndependentValuePath="Key" ItemsSource="{Binding [1]}"
IsSelectionEnabled="True" />
<chartingToolkit:LineSeries DependentValuePath="Value" IndependentValuePath="Key" ItemsSource="{Binding [2]}"
IsSelectionEnabled="True" />
<chartingToolkit:Chart.LegendStyle>
<Style TargetType="Control">
<Setter Property="Width" Value="0"/>
<Setter Property="Height" Value="0"/>
</Style>
</chartingToolkit:Chart.LegendStyle>
</chartingToolkit:Chart>
You need to set LinearAxis for the first chart, because you put ColumnSeries first and they use CategoryAxis instead of the correct one.
Here is the code for the first chart:
<chartingToolkit:Chart Name="lineChart1" Title="Series1" VerticalAlignment="Top" Margin="449,39,43,0" Height="262">
<chartingToolkit:Chart.Axes>
<chartingToolkit:LinearAxis Orientation="X" />
</chartingToolkit:Chart.Axes>
...
The code of the second chart is correct, but the chart looks bad because of the data that you use for binding.
Post C# code where you set the DataContext property and post what values you use there.

How to remove the dots in Wpf Chart which is using Data Visualzation tool kit dll

I am working MVVM & Wpf Application, in that I am developing a chart using Data visualization tool kit Chart Line series...
This is my Xaml Code..
xmlns:chartingToolkit="clr-namespace:System.Windows.Controls.DataVisualization.Charting; assembly=System.Windows.Controls.DataVisualization.Toolkit"
<chartingToolkit:Chart>
<chartingToolkit:LineSeries
DataContext="{Binding}"
DependentValueBinding="{Binding Path=y}"
IndependentValueBinding="{Binding Path=x}"
ItemsSource="{Binding Path=Data}" >
</chartingToolkit:LineSeries>
<chartingToolkit:Chart.Axes>
<chartingToolkit:LinearAxis ShowGridLines="False" Orientation="X" Interval="0">
</chartingToolkit:LinearAxis>
<chartingToolkit:LinearAxis ShowGridLines="False" Orientation="Y" Interval="0">
</chartingToolkit:LinearAxis>
</chartingToolkit:Chart.Axes>
</chartingToolkit:Chart>
I am able to display my chart, but the problem is how to hide dots. (I marked them with pink Circle in the picture (graph/ chart))
You have to set a style with Opacity = 0
<Style x:Key="LineDataPointStyle" TargetType="{x:Type chartingToolkit:LineDataPoint}">
<Setter Property="Background" Value="Blue" ></Setter>
<Setter Property="Opacity" Value="0" />
</Style>
<chartingToolkit:LineSeries
Title="Line"
ItemsSource="{Binding}"
IndependentValuePath="Int"
DependentValuePath="LineValue"
DataPointStyle="{StaticResource LineDataPointStyle}"/>

Binding the background colour of a control using a trigger in WPF/XAML

Okay, first off I have no experience of WPF whatsoever so please bear with me and apologies if my terminology is a little wayward... ;)
The following code snippet is part of a WPF application that I have inherited. The trigger governs whether mandatory fields on a particular form are highlighted or not. The code works but the highlighting seems to apply to the control and the border (??) which contains it.
<ItemsControl xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:cal="clr-namespace:Caliburn.PresentationFramework.ApplicationModel;assembly=Caliburn.PresentationFramework"
x:Class="company.product.Jobs.JobParametersEditor"
IsTabStop="False">
<ItemsControl.ItemTemplate>
<DataTemplate>
<DockPanel MinHeight="30">
<TextBlock Text="{Binding DisplayName, Mode=OneWay}"
DockPanel.Dock="Left"
VerticalAlignment="Center"
MinWidth="120"
Margin="6,0" />
<Border>
<Border.Style>
<Style TargetType="{x:Type Border}">
<Setter Property="Background"
Value="{x:Null}" />
<Style.Triggers>
<DataTrigger Binding="{Binding IsValid}"
Value="False">
<Setter Property="Background"
Value="Red" />
</DataTrigger>
</Style.Triggers>
</Style>
</Border.Style>
<ContentControl cal:View.Model="{Binding ValueEditor}"
ToolTip="{Binding ToolTip}"
IsTabStop="False"
MinHeight="19"
VerticalAlignment="Center"
HorizontalAlignment="Stretch" />
</Border>
</DockPanel>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
The result is a bit clunky so I would like to restrict the highlighting to the control only but I can't figure out how to do it. I've tried moving the trigger so that it applies to the ContentControl instead of the Border but that didn't work and fiddling about with border margins, padding and thickness hasn't had any effect either.
Could anybody enlighten me as to how to accomplish this?

Efficiently display text on image in WPF?

How to display text on an image, so it should always visible (because the image colors are mixed and unpredictable)?
I thought about two options:
Making the text border in white while the text itself will be black
Having the text displayed negatively to the picture
The 1st option would be preferred since it looks more solid.
Embedding the text is simple:
<Grid>
<Image Source="{Binding ImageLink}" Width="110" />
<TextBlock Text="{Binding Description}"
HorizontalAlignment="Center"
VerticalAlignment="Center" />
</Grid>
Update on answer:
Sounds like a great idea except it doesn't work.
I tried your code, and here are the results:
The left image is when I set the Color property to White and ShadowDepth to 10.
I did this and it helps:
<Style x:Key="AnnotationStyle" TargetType="TextBlock">
<Setter Property="Background" Value="#70FFFFFF" />
<Setter Property="FontWeight" Value="Bold" />
<Setter Property="HorizontalAlignment" Value="Center"/>
<Setter Property="VerticalAlignment" Value="Center"/>
<Setter Property="TextAlignment" Value="Center"/>
<Setter Property="TextWrapping" Value="Wrap"/>
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Background" Value="#CCFFFFFF" />
</Trigger>
</Style.Triggers>
</Style>
....
<TextBlock ... Style="{StaticResource AnnotationStyle}"/>
Here is what it looks like:
The best way to make the text more highlighted or contrasted is by using any effect, particularly the shader effects.
Microsoft is also make bitmap effect obsoleted since .NET 3.5 SP1, therefore your best bet is using any shader effect or create your own.
For example (from Karl Shifflett), you can use DropShadowEffect to "outline" your text but set the ShadowDepth to 0:
<Grid>
<Image Source="{Binding ImageLink}" Width="110" />
<TextBlock Text="{Binding Description}"
HorizontalAlignment="Center"
VerticalAlignment="Center">
<TextBlock.Effect>
<DropShadowEffect ShadowDepth="0" Color="Blue" BlurRadius="10" />
</TextBlock.Effect>
</TextBlock>
</Grid>
For more sample, you can google WPF effects.
UPDATE: You can also turn off antialiasing on text by using attached property of TextOptions.TextRenderingMode and set it to "Aliased", or you can also use TextOptions.TextFormattingMode and set to "Display".
Try and compare this and see if it will fit your needs:
<StackPanel>
<TextBlock>
Hello World ... Ideal text formatting
</TextBlock>
<TextBlock TextOptions.TextFormattingMode="Display">
Hello World ... Display text formatting
</TextBlock>
</StackPanel>
Hope this helps.

WPF Charting: how to collapse datapoint dots in lineseries

I have multiple line series in a chart. Chart lines are drawn first and then dots follow the lines. It's annoying and the size of big dots makes large datasets simply useless.
Currently I am doing this for each lineseries...
<chartingToolkit:LineSeries
Title="Socket 2"
Name="LineSocket2"
LegendItemStyle ="{StaticResource LegendItemStyle}"
IndependentValueBinding="{Binding timestamp}"
DependentValueBinding="{Binding wattage}"
ToolTip="Socket 2">
<chartingToolkit:LineSeries.DataPointStyle>
<Style TargetType="{x:Type chartingToolkit:LineDataPoint}">
<Setter Property="Visibility" Value="Collapsed"/>
</Style>
</chartingToolkit:LineSeries.DataPointStyle>
</chartingToolkit:LineSeries>
But it doesn't do what I want.
How can it be done?
If it helps anyone, the following works for me:
<chartingToolkit:Chart DataContext="1,10 2,20 3,30 4,40" HorizontalAlignment="Stretch" Margin="-1,14,0,0" Name="chart1" Title="Chart Title" VerticalAlignment="Stretch" Width="806" Height="Auto">
<chartingToolkit:LineSeries Name="Series1" DependentValuePath="X" IndependentValuePath="Y" ItemsSource="{Binding}">
<chartingToolkit:LineSeries.DataPointStyle>
<Style TargetType="chartingToolkit:LineDataPoint">
<Setter Property="Opacity" Value="0" />
<Setter Property="Background" Value="Blue" />
</Style>
</chartingToolkit:LineSeries.DataPointStyle>
</chartingToolkit:LineSeries>
</chartingToolkit:Chart>
The charting toolkit is actually a derivative of the Charting in the Silverlight toolkit.
Hence the answer to the question removing-collapsing-datapoints-in-a-lineseries may work for you.

Resources