LiveCharts文档-3开始-7标签
LiveCharts文档-3开始-7标签
Label就是Chart中表示数值的字符串,通常被放置在轴的位置和提示当中。
下图中的这些字符串显示的都是标签
using System;
using System.Windows.Forms;
using LiveCharts;
using LiveCharts.Defaults;
using LiveCharts.Wpf;
namespace Winforms.Cartesian.Labels
{
public partial class Labels : Form
{
public Labels()
{
InitializeComponent();
}
private void Labels_Load(object sender, EventArgs e)
{
cartesianChart1.Series.Add(new ColumnSeries
{
Values = new ChartValues<ObservableValue>
{
new ObservableValue(4),
new ObservableValue(2),
new ObservableValue(8),
new ObservableValue(2),
new ObservableValue(3),
new ObservableValue(0),
new ObservableValue(1),
},
DataLabels = true,
LabelPoint = point => point.Y + "K"
});
cartesianChart1.AxisX.Add(new Axis
{
Labels = new[]
{
"Shea Ferriera",
"Maurita Powel",
"Scottie Brogdon",
"Teresa Kerman",
"Nell Venuti",
"Anibal Brothers",
"Anderson Dillman"
},
Separator = new Separator // force the separator step to 1, so it always display all labels
{
Step = 1,
IsEnabled = false //disable it to make it invisible.
},
LabelsRotation = 15
});
cartesianChart1.AxisY.Add(new Axis
{
LabelFormatter = value => value + ".00K items",
Separator = new Separator()
});
}
}
}
LiveCharts有两种类型的Label,格式化类型和映射类型。
格式化类型
当Chart当中的值和label之间存在直接转换的时候,格式化类型的Label会很有用。比如,在下面的图片中,Y轴值的范围从8到26,但是因为现在的格式化器的作用,我们能够看到8被显示为8.00k。
Axis.LabelFormatter 可以使用double类型的值作为输入,返回一个string,LiveCharts每次在需要将表的值显示为字符串的时候,就会使用这个函数。
MyAxis.LabelFormatter = val => val.ToString("C"); //as currency
MyAxis.LabelFormatter = val => val + "°"; //as degrees
MyAxis.LabelFormatter = val => val + ".00 items sold"; //or any other custom format
映射类型
当需要用一个名称映射位置的时候,映射类型会很有用,比如第一个点属于john,第二个属于susan,第三个属于charles。
cartesianChart1.AxisX.Add(new LiveCharts.Wpf.Axis
{
Labels = new[]
{
"Shea Ferriera",
"Maurita Powel",
"Scottie Brogdon",
"Teresa Kerman",
"Nell Venuti",
"Anibal Brothers",
"Anderson Dillman"
}
});
映射类型意味着,轴的值将会用Axis.Labels属性当中的字符串来表示,Axis.Labels类型是IList 所以当轴的值是0的时候,标签使用的就是Labels[0],以此类推。
请注意到轴的值大于Labels的总数的时候,会返回空字符串。
Axis.Labels隐藏了一个Axis.LabelFormatte,因此当Axis.Labels不是null,那么标签将会从Axis.Labels中找,如果Axis.Labels是null,那么Livecharts将会使用格式化器,如果都是null,那么原始值会被返回。
数据标签
当你需要你的series上的每个点都有一个标签的时候,设置Series.DataLabels属性为true即可。如果必要的话,可以自定义数据标签,使用Series.LabelPoint 属性
new ColumnSeries
{
Values = new ChartValues>double> { 4, 2, 8, 2, 3, 0, 1 },
DataLabels = true,
LabelPoint = point => point.Y + "K"
}
旋转标签
有时候你的标签长度过长,你就需要权衡一下位置,这时候你就可以旋转标签,可以使用任何角度,甚至是负的角度(反方向旋转)。
cartesianChart1.AxisX.Add(new LiveCharts.Wpf.Axis
{
Labels = new[]
{
"Shea Ferriera",
"Maurita Powel",
"Scottie Brogdon",
"Teresa Kerman",
"Nell Venuti",
"Anibal Brothers",
"Anderson Dillman"
},
LabelsRotation = 13,
Separator = new Separator // force the separator step to 1, so it always display all labels
{
Step = 1, // if you don't force the separator, it will be calculated automatically, and could skip some labels
IsEnabled = false //disable it to make it invisible.
}
});
LiveCharts文档-3开始-7标签的更多相关文章
- LiveCharts文档-3开始-6轴Axes
原文:LiveCharts文档-3开始-6轴Axes LiveCharts文档-3开始-6轴Axes 通常来说,你可以自定义LiveChart里的任何东西,Axes也不例外.下面这幅图展示了Axes. ...
- LiveCharts文档-4基本绘图-3其他
原文:LiveCharts文档-4基本绘图-3其他 4基本绘图-3其他 因为每个图表的使用方法大同小异,所以不再啰嗦重复,具体直接看这个链接里的介绍.原文链接 其他的图表类型有 基本堆叠图 基本条形图 ...
- LiveCharts文档-3开始-8自定义工具提示
原文:LiveCharts文档-3开始-8自定义工具提示 LiveCharts文档-3开始-8自定义工具提示 默认每个需要tooltip或者legend的chart都会初始化一个DefaultLeng ...
- LiveCharts文档-4基本绘图-1基本线条图
原文:LiveCharts文档-4基本绘图-1基本线条图 4基本绘图-1基本线条图 using System; using System.Windows.Forms; using System.Win ...
- LiveCharts文档-4基本绘图-2基本柱形图
原文:LiveCharts文档-4基本绘图-2基本柱形图 4基本绘图-2基本柱形图 using System.Windows.Forms; using LiveCharts; using LiveCh ...
- LiveCharts文档-3开始-4可用的图表
原文:LiveCharts文档-3开始-4可用的图表 LiveCharts文档-3开始-4可用的图表 LiveCharts共有5类图表,你将会在后面的章节当中看到这些图表的使用方法. Cartesia ...
- LiveCharts文档-3开始-5序列Series
原文:LiveCharts文档-3开始-5序列Series LiveCharts文档-3开始-5序列Series Strokes和Fills 笔触和填充 所有的Series都有笔触和填充属来处理颜色, ...
- LiveCharts文档-3开始-2基础
原文:LiveCharts文档-3开始-2基础 LiveCharts文档-3开始-2基础 基本使用 LiveCharts设计的很容易使用,所有的东西都可以自动的实现更新和动画,库会在它觉得有必要更新的 ...
- LiveCharts文档-3开始-3类型和设置
原文:LiveCharts文档-3开始-3类型和设置 LiveCharts文档-3开始-3类型和设置 类型和设置 这一部分非常的重要,涉及到LiveCharts的基本构成单元的介绍 LiveChart ...
随机推荐
- modifyGeoJSON
from osgeo import ogr import json from geojson import loads, dumps, Feature, FeatureCollection from ...
- spring cloud 配置文件application.yml和bootstrap.yml 的定位,区别和联系总算是有一点明白了
最近在启用springcloud配置中心server的东西,在整理属性资源的时候,突然发现:用了这么久的springboot,为什么会配置两个属性文件同时存在(application.yml/prop ...
- K邻近分类算法
# -*- coding: utf-8 -*- """ Created on Thu Jun 28 17:16:19 2018 @author: zhen "& ...
- JS获取当前星期几的简易写法
var str = "今天是星期" + "日一二三四五六".charAt(new Date().getDay()); mark在此,方便日后复制 原文https ...
- vue_模板渲染
渲染 当获取到后端数据后,我们会把它按照一定的规则加载到写好的模板中,输出成在浏览器中显示的HTML,这个过程就称之为渲染. vue.js是在前端(即浏览器内)进行的模板渲染. 前后端渲染对比 前端渲 ...
- P1056 排座椅
非原创 #include<bits/stdc++.h>using namespace std;int t1[2009];int t2[2009]; int findmax(int *a){ ...
- oracle sqlplus 回退键以及上下键
Linux中安装完Oracle后,默认的 sqlplus 上下键是不能用的,安装了 rlwrap 之后就能通过上下键翻回历史命令了 下载地址 https://github.com/hanslub42/ ...
- 1095 Anigram单词
基准时间限制:1 秒 空间限制:131072 KB 分值: 10 难度:2级算法题 收藏 关注 一个单词a如果通过交换单词中字母的顺序可以得到另外的单词b,那么定义b是a的Anigram,例如单词 ...
- (6)sudo命令详解(每周一个linux命令系列)
首先说句抱歉,最近事情比较复杂,停更了一阵子.我又回来啦 多用户管理 我们常用的windows个人系统虽然可以设置多用户,但是实际上是不可以多用户同时登陆的(这个我实验过,我以前用windows服务器 ...
- 简单的CSS圆形缩放动画
简单的CSS圆形缩放动画 话不多说鼠标移动上去,看效果吧,效果预览 代码如下: <!DOCTYPE html> <html> <head> <title> ...