LightningChart.NET如何使用两个BarSeries创建简单的2D图表

2023-10-12 17:58

本文主要是介绍LightningChart.NET如何使用两个BarSeries创建简单的2D图表,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

本教程介绍了如何使用两个BarSeries创建简单的2D图表。
BarSeries将数据值表示为矩形条,并且可以用于以非常清晰的方式可视化数据之间的差异和方差。
在本教程中,BarSeries用于表示两年期间的每月平均温度。
本教程假定您已在WinForms或WPF应用程序上使用LightningChart创建了新图表。如果没有,请按照我们的简单2D图表创建应用程序。

在这里插入图片描述

1.创建一个新的BarSeries并为创建的系列添加样式。

您可以使用System.Windows.Media.Color或System.Drawing.Color定义颜色,具体取决于您使用的是WPF还是WinForms。
// Create a new BarSeries.
var barSeries1 = new BarSeries(chart.ViewXY, axisX, axisY);

// Add styling to created series.
barSeries1.Fill.Color = Color.FromRgb(255, 165, 0); // Orange.
barSeries1.Fill.GradientFill = GradientFill.Solid;
barSeries1.Title.Text = “2017”;
barSeries1.BarThickness = 10;

2.生成数据作为BarSeriesValues来代表平均每月温度并将其添加到BarSeries。

// Generate data as BarSeriesValues.
BarSeriesValue[] bars1 = new BarSeriesValue[]
{
new BarSeriesValue(0, -5, null),
new BarSeriesValue(1, -6, null),
new BarSeriesValue(2, -2, null),
new BarSeriesValue(3, 4, null),
new BarSeriesValue(4, 10, null),
new BarSeriesValue(5, 14, null),
new BarSeriesValue(6, 17, null),
new BarSeriesValue(7, 15, null),
new BarSeriesValue(8, 10, null),
new BarSeriesValue(9, 6, null),
new BarSeriesValue(10, -2, null),
new BarSeriesValue(11, -4, null)
};

// Add BarSeriesValues to BarSeries.
barSeries1.Values = bars1;

3.将BarSeries添加到图表中。

// Add BarSeries to chart.
chart.ViewXY.BarSeries.Add(barSeries1);

4.创建第二个BarSeries并为创建的系列添加样式。

// Create second BarSeries.
var barSeries2 = new BarSeries();

// Add styling to created series.
barSeries2.Fill.Color = Color.FromRgb(211, 211, 211); // LightGray.
barSeries2.Fill.GradientFill = GradientFill.Solid;
barSeries2.Title.Text = “2018”;
barSeries2.BarThickness = 10;

5.生成另一组数据作为BarSeriesValues,以表示平均每月温度并将其添加到BarSeries。

BarSeriesValue[] bars2 = new BarSeriesValue[]
{
new BarSeriesValue(0, -1, null),
new BarSeriesValue(1, -1, null),
new BarSeriesValue(2, 2, null),
new BarSeriesValue(3, 8, null),
new BarSeriesValue(4, 15, null),
new BarSeriesValue(5, 19, null),
new BarSeriesValue(6, 21, null),
new BarSeriesValue(7, 19, null),
new BarSeriesValue(8, 14, null),
new BarSeriesValue(9, 8, null),
new BarSeriesValue(10, 2, null),
new BarSeriesValue(11, -7, null)
};

// Add BarSeriesValues to BarSeries.
barSeries2.Values = bars2;

6.将BarSeries添加到图表。

// Add BarSeries to chart.
chart.ViewXY.BarSeries.Add(barSeries2);
LightningChart提供BarViewOptions属性,用于自定义条形图在图表上的显示方式。
BarViewOptions.Grouping允许设置条形图,以按值索引,按宽度拟合的索引或按位置值绘制图表。
在本教程中,分组是使用ByLocation -option 完成的。

7.配置BarSeries的条形视图布局。

// Configure bar view layout.
chart.ViewXY.BarViewOptions.Grouping = BarsGrouping.ByLocation;
LightningChart提供了可能性,通过添加自己的自定义蜱作为轴值CustomAxisTicks。
在本教程中,CustomAxisTicks用于将月份名称显示为X轴值。
// Create list of months.
string[] months = new string[]
{
“January”,
“February”,
“March”,
“April”,
“May”,
“June”,
“July”,
“August”,
“September”,
“October”,
“November”,
“December”
};

// Create CustomAxisTicks to display months as X-axis values.
for (int i = 0; i < months.Length; i++)
{
CustomAxisTick tick = new CustomAxisTick(axisX);
tick.AxisValue = i;
tick.LabelText = months[i];
tick.Color = Color.FromArgb(35, 255, 255, 255);

axisX.CustomTicks.Add(tick);

}

// Notify chart about set custom axis ticks.
axisX.InvalidateCustomTicks();
注意!为了正确显示自定义轴刻度,请记住将AutoFormatLabels属性设置为false并将CustomTicksEnabled属性设置为true。
// Disable autoformating of labels.
axisX.AutoFormatLabels = false;

// Enable CustomAxisTicks.
axisX.CustomTicksEnabled = true;

本文章除转载自【慧都科技】。欢迎任何形式的转载,但请务必注明出处、不得修改原文相关链接,尊重他人劳动成果

这篇关于LightningChart.NET如何使用两个BarSeries创建简单的2D图表的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/197491

相关文章

Java中的Cursor使用详解

《Java中的Cursor使用详解》本文介绍了Java中的Cursor接口及其在大数据集处理中的优势,包括逐行读取、分页处理、流控制、动态改变查询、并发控制和减少网络流量等,感兴趣的朋友一起看看吧... 最近看代码,有一段代码涉及到Cursor,感觉写法挺有意思的。注意是Cursor,而不是Consumer

Node.js net模块的使用示例

《Node.jsnet模块的使用示例》本文主要介绍了Node.jsnet模块的使用示例,net模块支持TCP通信,处理TCP连接和数据传输,具有一定的参考价值,感兴趣的可以了解一下... 目录简介引入 net 模块核心概念TCP (传输控制协议)Socket服务器TCP 服务器创建基本服务器服务器配置选项服

Java实战之利用POI生成Excel图表

《Java实战之利用POI生成Excel图表》ApachePOI是Java生态中处理Office文档的核心工具,这篇文章主要为大家详细介绍了如何在Excel中创建折线图,柱状图,饼图等常见图表,需要的... 目录一、环境配置与依赖管理二、数据源准备与工作表构建三、图表生成核心步骤1. 折线图(Line Ch

如何使用CSS3实现波浪式图片墙

《如何使用CSS3实现波浪式图片墙》:本文主要介绍了如何使用CSS3的transform属性和动画技巧实现波浪式图片墙,通过设置图片的垂直偏移量,并使用动画使其周期性地改变位置,可以创建出动态且具有波浪效果的图片墙,同时,还强调了响应式设计的重要性,以确保图片墙在不同设备上都能良好显示,详细内容请阅读本文,希望能对你有所帮助...

Rust中的注释使用解读

《Rust中的注释使用解读》本文介绍了Rust中的行注释、块注释和文档注释的使用方法,通过示例展示了如何在实际代码中应用这些注释,以提高代码的可读性和可维护性... 目录Rust 中的注释使用指南1. 行注释示例:行注释2. 块注释示例:块注释3. 文档注释示例:文档注释4. 综合示例总结Rust 中的注释

Linux使用cut进行文本提取的操作方法

《Linux使用cut进行文本提取的操作方法》Linux中的cut命令是一个命令行实用程序,用于从文件或标准输入中提取文本行的部分,本文给大家介绍了Linux使用cut进行文本提取的操作方法,文中有详... 目录简介基础语法常用选项范围选择示例用法-f:字段选择-d:分隔符-c:字符选择-b:字节选择--c

使用Go语言开发一个命令行文件管理工具

《使用Go语言开发一个命令行文件管理工具》这篇文章主要为大家详细介绍了如何使用Go语言开发一款命令行文件管理工具,支持批量重命名,删除,创建,移动文件,需要的小伙伴可以了解下... 目录一、工具功能一览二、核心代码解析1. 主程序结构2. 批量重命名3. 批量删除4. 创建文件/目录5. 批量移动三、如何安

springboot的调度服务与异步服务使用详解

《springboot的调度服务与异步服务使用详解》本文主要介绍了Java的ScheduledExecutorService接口和SpringBoot中如何使用调度线程池,包括核心参数、创建方式、自定... 目录1.调度服务1.1.JDK之ScheduledExecutorService1.2.spring

Java使用Tesseract-OCR实战教程

《Java使用Tesseract-OCR实战教程》本文介绍了如何在Java中使用Tesseract-OCR进行文本提取,包括Tesseract-OCR的安装、中文训练库的配置、依赖库的引入以及具体的代... 目录Java使用Tesseract-OCRTesseract-OCR安装配置中文训练库引入依赖代码实

Java中对象的创建和销毁过程详析

《Java中对象的创建和销毁过程详析》:本文主要介绍Java中对象的创建和销毁过程,对象的创建过程包括类加载检查、内存分配、初始化零值内存、设置对象头和执行init方法,对象的销毁过程由垃圾回收机... 目录前言对象的创建过程1. 类加载检查2China编程. 分配内存3. 初始化零值4. 设置对象头5. 执行