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

相关文章

使用Vue-ECharts实现数据可视化图表功能

《使用Vue-ECharts实现数据可视化图表功能》在前端开发中,经常会遇到需要展示数据可视化的需求,比如柱状图、折线图、饼图等,这类需求不仅要求我们准确地将数据呈现出来,还需要兼顾美观与交互体验,所... 目录前言为什么选择 vue-ECharts?1. 基于 ECharts,功能强大2. 更符合 Vue

如何合理使用Spring的事务方式

《如何合理使用Spring的事务方式》:本文主要介绍如何合理使用Spring的事务方式,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录1、介绍1.1、底层构造1.1.事务管理器1.2.事务定义信息1.3.事务状态1.4.联系1.2、特点1.3、原理2. Sprin

Vue中插槽slot的使用示例详解

《Vue中插槽slot的使用示例详解》:本文主要介绍Vue中插槽slot的使用示例详解,本文通过实例代码给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友参考下吧... 目录一、插槽是什么二、插槽分类2.1 匿名插槽2.2 具名插槽2.3 作用域插槽三、插槽的基本使用3.1 匿名插槽

使用WPF实现窗口抖动动画效果

《使用WPF实现窗口抖动动画效果》在用户界面设计中,适当的动画反馈可以提升用户体验,尤其是在错误提示、操作失败等场景下,窗口抖动作为一种常见且直观的视觉反馈方式,常用于提醒用户注意当前状态,本文将详细... 目录前言实现思路概述核心代码实现1、 获取目标窗口2、初始化基础位置值3、创建抖动动画4、动画完成后

PyQt5 QDate类的具体使用

《PyQt5QDate类的具体使用》QDate是PyQt5中处理日期的核心类,本文主要介绍了PyQt5QDate类的具体使用,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价... 目录核心功能常用方法及代码示例​1. 创建日期对象​2. 获取日期信息​3. 日期计算与比较​4. 日

Go语言使用slices包轻松实现排序功能

《Go语言使用slices包轻松实现排序功能》在Go语言开发中,对数据进行排序是常见的需求,Go1.18版本引入的slices包提供了简洁高效的排序解决方案,支持内置类型和用户自定义类型的排序操作,本... 目录一、内置类型排序:字符串与整数的应用1. 字符串切片排序2. 整数切片排序二、检查切片排序状态:

使用Java将实体类转换为JSON并输出到控制台的完整过程

《使用Java将实体类转换为JSON并输出到控制台的完整过程》在软件开发的过程中,Java是一种广泛使用的编程语言,而在众多应用中,数据的传输和存储经常需要使用JSON格式,用Java将实体类转换为J... 在软件开发的过程中,Java是一种广泛使用的编程语言,而在众多应用中,数据的传输和存储经常需要使用j

Nginx使用Keepalived部署web集群(高可用高性能负载均衡)实战案例

《Nginx使用Keepalived部署web集群(高可用高性能负载均衡)实战案例》本文介绍Nginx+Keepalived实现Web集群高可用负载均衡的部署与测试,涵盖架构设计、环境配置、健康检查、... 目录前言一、架构设计二、环境准备三、案例部署配置 前端 Keepalived配置 前端 Nginx

Python logging模块使用示例详解

《Pythonlogging模块使用示例详解》Python的logging模块是一个灵活且强大的日志记录工具,广泛应用于应用程序的调试、运行监控和问题排查,下面给大家介绍Pythonlogging模... 目录一、为什么使用 logging 模块?二、核心组件三、日志级别四、基本使用步骤五、快速配置(bas

使用animation.css库快速实现CSS3旋转动画效果

《使用animation.css库快速实现CSS3旋转动画效果》随着Web技术的不断发展,动画效果已经成为了网页设计中不可或缺的一部分,本文将深入探讨animation.css的工作原理,如何使用以及... 目录1. css3动画技术简介2. animation.css库介绍2.1 animation.cs