您可以为应用程序中的任何图表设置default style,必须根据需要选择颜色、大小和weight。
Colors:
这组颜色将是在您的Series中使用的默认颜色,当Series的数量大于主题中的颜色数时,则颜色将重复。
- Material,based on material design from Google基于谷歌的材料设计
- Metro, based on MoedernUi design基于MoedernUi的设计
- Blue, a scale of blues蓝调音阶
- White, a scale of light colors浅色的刻度
- Black, a scale of dark colors深色的刻度
Size:
大小决定了Axis和Series.DataLabels的字体大小,它还设置了Series.PointGetimeySize的默认大小,选项有小(S)、中(M)和大(L)。
Weight:
权重定义了Axis.Separator笔画厚度和行程破折号数组,它还定义了默认的Series.StrokeThickness属性,选项是轻量的、普通的和粗体的。
例子:
在解决方案资源管理器中,打开App.xaml并向应用程序资源中添加一个ResourceDictionary,在此字典中选择a颜色集、大小和weight,如下面的代码所示,在本例中,我们使用的是材料设计颜色、中等大小和正常weight
<Application x:Class="Wpf.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
StartupUri="MainWindow.xaml">
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<!--Select colors set, options are material, metro, blue, white and black-->
<!--Material design colors--><ResourceDictionary Source="pack://application:,,,/LiveCharts.Wpf;component/Themes/Colors/material.xaml" />
<!--Metro colors--><!--<ResourceDictionary Source="pack://application:,,,/LiveCharts.Wpf;component/Themes/Colors/metro.xaml" />-->
<!--Blue gradient--><!--<ResourceDictionary Source="pack://application:,,,/LiveCharts.Wpf;component/Themes/Colors/blue.xaml" />-->
<!--white gradient--><!--<ResourceDictionary Source="pack://application:,,,/LiveCharts.Wpf;component/Themes/Colors/white.xaml" />-->
<!--black gradient--><!--<ResourceDictionary Source="pack://application:,,,/LiveCharts.Wpf;component/Themes/Colors/black.xaml" />-->
<!--Select size, options are small, medium and large-->
<!--small--><!--<ResourceDictionary Source="pack://application:,,,/LiveCharts.Wpf;component/Themes/Size/s.xaml" />-->
<!--medium--><ResourceDictionary Source="pack://application:,,,/LiveCharts.Wpf;component/Themes/Size/m.xaml" />
<!--large--><!--<ResourceDictionary Source="pack://application:,,,/LiveCharts.Wpf;component/Themes/Size/l.xaml" />-->
<!--Select weight, options are light, normal and bold-->
<!--light--><!--<ResourceDictionary Source="pack://application:,,,/LiveCharts.Wpf;component/Themes/Weight/light.xaml" />-->
<!--normal--><ResourceDictionary Source="pack://application:,,,/LiveCharts.Wpf;component/Themes/Weight/normal.xaml" />
<!--bold--><!--<ResourceDictionary Source="pack://application:,,,/LiveCharts.Wpf;component/Themes/Weight/bold.xaml" />-->
<!--Also add the base theme, this is required always-->
<ResourceDictionary Source="pack://application:,,,/LiveCharts.Wpf;component/Themes/base.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
</Application>
Custom Style
您还可以编写自己的主题,下面是一个基本框架的示例:
<Application x:Class="Wpf.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:lvc="clr-namespace:LiveCharts.Wpf"
xmlns:system="clr-namespace:System;assembly=mscorlib"
StartupUri="MainWindow.xaml">
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<lvc:ColorsCollection x:Key="ColorsCollection">
<Color A="255" R="33" G="149" B="242" />
<Color A="255" R="243" G="67" B="54" />
<Color A="255" R="254" G="192" B="7" />
<Color A="255" R="96" G="125" B="138" />
<Color A="255" R="232" G="30" B="99" />
<Color A="255" R="76" G="174" B="80" />
<Color A="255" R="63" G="81" B="180" />
<Color A="255" R="204" G="219" B="57" />
</lvc:ColorsCollection>
<system:Double x:Key="Size">12</system:Double>
<system:Double x:Key="SeparatorStrokeThickness">1.8</system:Double>
<DoubleCollection x:Key="SeparatorStrokeDashArray">3</DoubleCollection>
<system:Double x:Key="SeriesStrokeThickness">3.0</system:Double>
<Style TargetType="lvc:CartesianChart">
<Setter Property="AnimationsSpeed" Value="0:0:0.420"></Setter>
<Setter Property="SeriesColors" Value="{StaticResource ColorsCollection}"/>
</Style>
<Style TargetType="lvc:Axis">
<Setter Property="FontSize" Value="{StaticResource Size}"></Setter>
<Setter Property="FontFamily" Value="Calibri"></Setter>
<Setter Property="Foreground" Value="#99303030"></Setter>
</Style>
<Style TargetType="lvc:Separator">
<Setter Property="StrokeThickness" Value="{StaticResource SeparatorStrokeThickness}"></Setter>
<Setter Property="StrokeDashArray" Value="{StaticResource SeparatorStrokeDashArray}"></Setter>
<Setter Property="Stroke" Value="#1A303030"></Setter>
<Style.Triggers>
<Trigger Property="AxisOrientation" Value="X">
<Setter Property="IsEnabled" Value="False"></Setter>
</Trigger>
</Style.Triggers>
</Style>
<Style TargetType="lvc:Series" x:Key="SeriesStyle">
<Setter Property="FontFamily" Value="Calibri"></Setter>
<Setter Property="FontSize" Value="{StaticResource Size}"></Setter>
<Setter Property="StrokeThickness" Value="{StaticResource SeriesStrokeThickness}"></Setter>
</Style>
<Style TargetType="lvc:CandleSeries" BasedOn="{StaticResource SeriesStyle}"/>
<Style TargetType="lvc:ColumnSeries" BasedOn="{StaticResource SeriesStyle}"/>
<Style TargetType="lvc:HeatSeries" BasedOn="{StaticResource SeriesStyle}"/>
<Style TargetType="lvc:LineSeries" BasedOn="{StaticResource SeriesStyle}">
<Setter Property="PointGeometrySize" Value="{StaticResource Size}"></Setter>
</Style>
<Style TargetType="lvc:StepLineSeries" BasedOn="{StaticResource SeriesStyle}">
<Setter Property="PointGeometrySize" Value="{StaticResource Size}"></Setter>
</Style>
<Style TargetType="lvc:VerticalLineSeries" BasedOn="{StaticResource SeriesStyle}">
<Setter Property="PointGeometrySize" Value="{StaticResource Size}"></Setter>
</Style>
<Style TargetType="lvc:OhlcSeries" BasedOn="{StaticResource SeriesStyle}"/>
<Style TargetType="lvc:RowSeries" BasedOn="{StaticResource SeriesStyle}"/>
<Style TargetType="lvc:ScatterSeries" BasedOn="{StaticResource SeriesStyle}"/>
<Style TargetType="lvc:StackedAreaSeries" BasedOn="{StaticResource SeriesStyle}"/>
<Style TargetType="lvc:StackedColumnSeries" BasedOn="{StaticResource SeriesStyle}"/>
<Style TargetType="lvc:StackedRowSeries" BasedOn="{StaticResource SeriesStyle}"/>
<Style TargetType="lvc:VerticalStackedAreaSeries" BasedOn="{StaticResource SeriesStyle}"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
</Application>