Click here to Skip to main content
15,868,133 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
The following xaml Line Chart code works great, except it shows the diamonds for each data point on the two line graphs. I do not want to show them. In Forms there is something like LegendItem.ImageStyle but I can't seem to find the System.Windows.Controls.DataVisualization equivalent. Any help is greatly appreciated!

xmlns:dvc="clr-namespace:System.Windows.Controls.DataVisualization.Charting;assembly=System.Windows.Controls.DataVisualization.Toolkit"


<dvc:Chart Name="Chart1" Title="Test Chart" >
            <dvc:LineSeries Title="Humidity"
                            ItemsSource="{Binding Points, Delay=2500, IsAsync=False}"                              
                            IndependentValueBinding="{Binding ts}"
                            DependentValueBinding="{Binding Humidity}" 
                            >
                <dvc:LineSeries.DependentRangeAxis>
                    <dvc:LinearAxis Orientation="Y" Title="Humidity" 
                                    ShowGridLines="True"/>
                </dvc:LineSeries.DependentRangeAxis>

                <dvc:LineSeries.Template>
                    <!-- change the line color to green and set the thickness -->
                    <ControlTemplate TargetType="dvc:LineSeries">
                        <Canvas x:Name="PlotArea">
                            <Polyline x:Name="polyline"
                                          Points="{TemplateBinding Points}"                                           
                                          Style="{TemplateBinding PolylineStyle}"
                                          Stroke="Green" StrokeThickness="0.1" />
                        </Canvas>
                    </ControlTemplate>
                </dvc:LineSeries.Template>
            </dvc:LineSeries>

            <dvc:LineSeries Title="Temperature"
                            ItemsSource="{Binding Points, Delay=2500, IsAsync=False}"
                            IndependentValueBinding="{Binding ts}"
                            DependentValueBinding="{Binding Temperature}">

                <dvc:LineSeries.DependentRangeAxis >
                    <dvc:LinearAxis Orientation="Y" Title="Temperature"/>
                </dvc:LineSeries.DependentRangeAxis>
            </dvc:LineSeries>
            
            <dvc:Chart.Axes>
                <dvc:LinearAxis Orientation="X" Title="X-Axis" ShowGridLines="True"/>
            </dvc:Chart.Axes>
        </dvc:Chart>


What I have tried:

I cannot find any reference online to solve my problem.
Posted
Updated 26-Apr-21 23:33pm

1 solution

Try sonmething like this:

XAML
<Style x:Key="DataPointStyle1" TargetType="{x:Type dvc:LineDataPoint}">
    <Setter Property="Visibility" Value="Collapsed"/>
</Style>


(dvc is your xmlns namespace definition for the datavisualization control.

If you want to make this available for all line series all the time, put this style definition in app.xaml.

XAML
<dvc:Chart>
...
    <dvc:Chart.Series>
        <dvc:LineSeries DataPointStyle="{DynamicResource DataPointStyle1}" ...>
...


If you don't want to bother with specifying the data point style in the chart, remove the x:Key element in your custom style, and it will be applied to all line series by default.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900