LiveCharts文档-3开始-6轴Axes

LiveCharts文档-3开始-6轴Axes

通常来说,你可以自定义LiveChart里的任何东西,Axes也不例外。下面这幅图展示了Axes。
344964-20180115090957240-581686812.jpg

Title标题

可以使用Title属性给axis添加一个标签

myAxis.Title = "Population"

合并轴

当你想需要一些空间的时候,可以在chart中合并一些axis,可以将Axis.IsMerged属性设置为true。下面的图片展示了合并Axis和没有合并的Axis的区别。
344964-20180115091011303-610965681.png

轴定位

不管你有1个还是10个轴,你总是可以制定轴的堆叠位置;使用 Axis.Position属性, 可以通过 RightTop, LeftBottom等可选选项进行调整。

new Axis { Position = Position = AxisPosition.LeftBottom }

344964-20180115091020678-1961234363.jpg

强制分隔

每个轴分隔都是根据chart的尺寸,值的范围,自动计算的,但是有些时候你需要静态的风格符,比如每30s,每10个单位,另外一个比较有用的应用就是显示所有的标签,这种情况下,设定分隔步长为1,将会强迫chart绘制所有的labels。如果要移除所有步长,可以设置回null,这样它又可以自动计算了。
当然要注意,强制步长可能会产生严重的性能问题,如果没有正确使用,比如你的range是0到1000,如果你设置步长为1,那么它将绘制1000个分隔出来。
//设置步长为1

new Axis
{
    Separator = new Separator
    {
        Step = 1,
        IsEnabled = false
    }
}

//下面这个例子使用30s作为步长,可以去时间相关的章节查看更多。

new Axis
{
    Separator = new Separator
    {
        Step = TimeSpan.FromSeconds(30).Ticks,
        IsEnabled = false
    }
}

分隔的样式

notice setting Axis.Separator.IsEnabled property to false will make the separator invisible.
注意,如果设置Axis.Separator.IsEnabled 为false的话,分隔就会不可见。

cartesianChart1.AxisX.Add(new Axis
{
   IsMerged = true,
   Separator = new Separator
   {
      StrokeThickness = 1,
      StrokeDashArray = new System.Windows.Media.DoubleCollection(new double[] { 2 }),
      Stroke = new System.Windows.Media.SolidColorBrush(System.Windows.Media.Color.FromRgb(64, 79, 86))
   }
});
 
cartesianChart1.AxisY.Add(new Axis
{
   IsMerged = true,
   Separator = new Separator
   {
      StrokeThickness = 1.5,
      StrokeDashArray = new System.Windows.Media.DoubleCollection(new double[] { 4 }),
      Stroke = new System.Windows.Media.SolidColorBrush(System.Windows.Media.Color.FromRgb(64, 79, 86))
   }
});

本节完

转载于:https://www.cnblogs.com/newlifechou/p/8286643.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
可以通过设置 Axis.Labels 属性来绑定 WPF LiveCharts 中的标签。具体步骤如下: 1. 在 XAML 中创建 LiveChart 控件和 Axis 控件: ```xml <Grid> <lvc:CartesianChart x:Name="Chart"> <lvc:CartesianChart.AxisX> <lvc:Axis Title="X标题" Labels="{Binding XLabels}"> <lvc:Axis.Separator> <lvc:Separator Stroke="Gray" StrokeThickness="1"/> </lvc:Axis.Separator> </lvc:Axis> </lvc:CartesianChart.AxisX> <lvc:CartesianChart.AxisY> <lvc:Axis Title="Y标题" Labels="{Binding YLabels}"> <lvc:Axis.Separator> <lvc:Separator Stroke="Gray" StrokeThickness="1"/> </lvc:Axis.Separator> </lvc:Axis> </lvc:CartesianChart.AxisY> <lvc:LineSeries x:Name="LineSeries" Title="数据" Values="{Binding Data}" LineSmoothness="0.3"/> </lvc:CartesianChart> </Grid> ``` 2. 在 ViewModel 中创建 XLabels 和 YLabels 属性,并在构造函数中初始化它们: ```csharp public class ViewModel : INotifyPropertyChanged { private List<string> _xLabels; public List<string> XLabels { get { return _xLabels; } set { _xLabels = value; OnPropertyChanged("XLabels"); } } private List<string> _yLabels; public List<string> YLabels { get { return _yLabels; } set { _yLabels = value; OnPropertyChanged("YLabels"); } } private ChartValues<double> _data; public ChartValues<double> Data { get { return _data; } set { _data = value; OnPropertyChanged("Data"); } } public ViewModel() { // 初始化 XLabels 和 YLabels XLabels = new List<string> { "Label1", "Label2", "Label3", "Label4", "Label5" }; YLabels = new List<string> { "0", "10", "20", "30", "40", "50" }; // 初始化 Data Data = new ChartValues<double>(); Data.Add(10); Data.Add(20); Data.Add(30); Data.Add(40); Data.Add(50); } public event PropertyChangedEventHandler PropertyChanged; protected void OnPropertyChanged(string propertyName) { PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); } } ``` 3. 在 MainWindow 中设置 DataContext 并显示: ```csharp public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); DataContext = new ViewModel(); } } ``` 这样就可以在 LiveChart 中绑定标签了。其中 XLabels 和 YLabels 是绑定到 Axis 的 Labels 属性上,Data 是绑定到 Series 的 Values 属性上的。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值