WPF Charting: how to collapse datapoint dots in lineseries - wpf

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.

Related

In multiple Y axis graph, the axis shift issue in 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.

WPF Toolkit Chart - Custom tooltip - show complex dependent value

I have the following chart:
<cht:Chart ...>
<cht:Chart.Series>
<cht:LineSeries Name="LineSeries" Title="a"
DependentValueBinding="{Binding Path=Value}"
IndependentValueBinding="{Binding Path=Key}"
ItemsSource="{Binding Path=SourceCollection}"
IsSelectionEnabled="True"
DataPointStyle="{DynamicResource SmallPointStyle}">
</cht:LineSeries>
</cht:Chart.Series>
</cht:Chart>
And the DataPointStyle:
<Style TargetType="cht:LineDataPoint">
<Setter Property="Width" Value="2" />
<Setter Property="Height" Value="2" />
<Setter Property="DependentValueStringFormat" Value="{}{0:0.00}"/>
</Style>
<Style x:Key="SmallPointStyle" TargetType="cht:LineDataPoint" BasedOn="{StaticResource {x:Type cht:LineDataPoint}}">
<Setter Property="BorderBrush" Value="Orange"/>
<Setter Property="Background" Value="Orange"/>
</Style>
The source collection is a list of KeyValuePair.
The application works fine.
I encountered a problem because i want to use a collection of KeyValuePair> where doubleA is the data extracted and the doubleB is a normalised value of doubleA, based on a range. so i need to change the LineSeries to be:
<cht:Chart ...>
<cht:Chart.Series>
<cht:LineSeries Name="LineSeries" Title="a"
DependentValueBinding="{Binding Path=Value.Value}"
IndependentValueBinding="{Binding Path=Key}"
ItemsSource="{Binding Path=SourceCollection}"
IsSelectionEnabled="True"
DataPointStyle="{DynamicResource SmallPointStyle}">
</cht:LineSeries>
</cht:Chart.Series>
</cht:Chart>
It works as i expected, but i need to show in the tooltip the real value (Value.Key), not the DependentValue. is there anyway to accomplish that?
See this blog post for one possible solution.
You find the LineSeries data point style that you have to override here.
However, keep in mind that when you override the template you will not get any random colors anymore.
Good luck!

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}"/>

How to do styling of data grid?

here i want to give alternate color white and grey to grid row . i hv done many try but i can not do styling of grid .the code is here
<Style TargetType="{x:Type wpftoolkit:DataGrid}">
<Setter Property="Margin" Value="0" />
<Setter Property="BorderBrush" Value="#A6A6A6" />
<Setter Property="BorderThickness" Value="0,1,0,0"/>
<Setter Property="Background" Value="{StaticResource GridBgBrush}" />
<Setter Property="RowBackground" Value="White" />
<Setter Property="AlternatingRowBackground" Value="#FFF3F6FA" />
<Setter Property="GridLinesVisibility" Value="Horizontal" />
<Setter Property="HorizontalGridLinesBrush" Value="Transparent" />
<Setter Property="RowHeaderWidth" Value="0" />
</Style>
here StaticResource GridBgBrush define earlier on this file as`
plz give proper solution .thanks in advance.
Make sure that your style is either defined within the resources section of your XAML file (after your GridBgBrush, so that it can reference it), or in a ResourceDictionary in your App somewhere making it accessible from anywhere. Without seeing more, I can't tell you where your problem is coming from. That is the correct way to define your style and I have several examples of this working as expected if you're interested in seeing them.
Another thing to note in case you didn't know, is that DataGrid (along with DatePicker) was introduced into WPF v4.0. This makes the WPF Toolkit (at least for the purposes of the DataGrid) unnecessary if you can target that version. After saying that, I suppose there's the slight chance that if you weren't aware you were using one and then styling the other, your style wouldn't work.
<XmlDataProvider x:Key="myData" Source="Data.xml" IsAsynchronous="True" />
<Style TargetType="{x:Type DataGrid}" x:Key="myStyle">
<Setter Property="AlternatingRowBackground" Value="Red"/>
</Style>
<Grid>
<DataGrid ItemsSource="{Binding Source={StaticResource myData}, XPath=persons/person}" AutoGenerateColumns="False" Style="{StaticResource myStyle}">
<DataGrid.Columns>
<DataGridTemplateColumn>
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding XPath=firstname}" />
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<DataGridTemplateColumn>
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding XPath=lastname}" />
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
</DataGrid.Columns>
</DataGrid>
</Grid>
You need to set AlternationCount property too.

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.

Resources