MindFusion.Charting for WPF常见问题集锦:将DateTime值显示为轴上的标签

本文整理了用户在使用MindFusion.Charting for WPF常见的问题,希望对您有所帮助。

MindFusion.Charting for WPF支持所有主流的图表类型,以及许多自定义的图表功能。线形图表控件允许你创建折线图、面积图、散点图或它们之间的任何组合形式。条形图表控件支持创建集群、堆叠或重叠的条形和柱状图。饼图图表控件则允许你创建环形图表,并且还可对它们的厚度进行自定义调整。

本文整理了用户在使用MindFusion.Charting for WPF常见的问题,希望对您有所帮助。

MindFusion.Charting for WPF最新试用版

问:我想在图表轴上显示DateTime值。我使用数字作为点,但我不想显示这些数据,我想显示它附带的DateTime值。这可以用你的工具吗/strong>

答: Wpf的图表支持在任何图表轴上绘制自定义标签。自定义标签既可以在轴的间隔位置绘制,也可以在该轴的数据点位置绘制。

在您的情况下,我们假设您要在轴的数据点位置绘制从数据源获取的DateTime标签。这是你的代码:

//set the data source lineChart1.DataSource = data; //set the name of the property in the data source to bind to lineChart1.XLabelPath = "PurchaseDate"; //set the type of the labels for the X-axis lineChart1.XAxisSettings.LabelType = LabelType.CustomText; //set the position of the custom labels lineChart1.XAxisSettings.CustomLabelPosition = CustomLabelPosition.ChartDataPoints; //set the format of the labels lineChart1.XAxisSettings.LabelFormat = "MMMM dd";

请注意,设置标签的格式非常重要。如果不这样做,控件将尝试使用标准转换将DateTime值转换为字符串,结果将不会如预期的那样。

问:我有8个类别的数据,每个类别有3个不同的值。我想在堆积图表中显示这些类别,每个类别的名称作为标签但不知道如何操作。

答:您想要显示的内容可以通过在条形图控件中添加3个BarSeries来完成。然后,您可以将每个系列的XDataPath或YDataPath属性绑定到数据源中的相应字段。将条形的类型设置为堆叠。

以下是构建堆积柱形图的方法:

//the first series is predefined BarSeries series1 = barChart1.Series[0] as BarSeries; series1.YDataPath = "EuropeSales"; series1.XData = indexes; series1.BarType = BarType.VerticalStack;  BarSeries series2 = new BarSeries(); series2.YDataPath = "AsiaSales"; series2.XData = indexes; barChart1.Series.Add(series2); series2.BarType = BarType.VerticalStack;  BarSeries series3 = new BarSeries(); series3.YDataPath = "USASales"; series3.XData = indexes; barChart1.Series.Add(series3); series3.BarType = BarType.VerticalStack;

这是一个示例列表,其中包含用于绑定图表的数据:

var salesList = new List() { new Sales(){Category =“apples”,EuropeSales = 34,AsiaSales = 12,USASales = 24}, new Sales(){Category =“oranges”,EuropeSales = 23,AsiaSales = 17,USASales = 10} , new Sales(){Category =“bananas”,EuropeSales = 4,AsiaSales = 31,USASales = 27}, new Sales(){Category =“cherries”,EuropeSales = 8,AsiaSales = 9,USASales = 30} };

我们分配数据源并将X轴的标签类型设置为自定义文本。该XLabelPath属性设置,提供了自定义标签的字段的名称:

 barChart1.DataSource = salesList; barChart1.XAxisSettings.LabelType = LabelType.CustomText; barChart1.XLabelPath = "Category";

教程持续更新中,感兴趣的朋友记得持续关注后续教程~

相关推荐:

MindFusion.Diagramming for WinForms常见问题集锦

MindFusion.Diagramming for Java问题集锦

想要购买MindFusion.Charting for WPF 正版授权的朋友可以咨询官方客服

更多精彩内容,欢迎关注下方的微信公众号,及时获取产品最新资讯▼▼▼

图片2.jpg

标签:

来源:慧都

声明:本站部分文章及图片转载于互联网,内容版权归原作者所有,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!

上一篇 2019年7月24日
下一篇 2019年7月24日

相关推荐

发表回复

登录后才能评论