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

Stella981
• 阅读 631

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

LightningChart.NET使用两个BarSeries创建简单的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;

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

点赞
收藏
评论区
推荐文章
blmius blmius
2年前
MySQL:[Err] 1292 - Incorrect datetime value: ‘0000-00-00 00:00:00‘ for column ‘CREATE_TIME‘ at row 1
文章目录问题用navicat导入数据时,报错:原因这是因为当前的MySQL不支持datetime为0的情况。解决修改sql\mode:sql\mode:SQLMode定义了MySQL应支持的SQL语法、数据校验等,这样可以更容易地在不同的环境中使用MySQL。全局s
Jacquelyn38 Jacquelyn38
2年前
2020年前端实用代码段,为你的工作保驾护航
有空的时候,自己总结了几个代码段,在开发中也经常使用,谢谢。1、使用解构获取json数据let jsonData  id: 1,status: "OK",data: 'a', 'b';let  id, status, data: number   jsonData;console.log(id, status, number )
皕杰报表之UUID
​在我们用皕杰报表工具设计填报报表时,如何在新增行里自动增加id呢?能新增整数排序id吗?目前可以在新增行里自动增加id,但只能用uuid函数增加UUID编码,不能新增整数排序id。uuid函数说明:获取一个UUID,可以在填报表中用来创建数据ID语法:uuid()或uuid(sep)参数说明:sep布尔值,生成的uuid中是否包含分隔符'',缺省为
Souleigh ✨ Souleigh ✨
2年前
前端性能优化 - 雅虎军规
无论是在工作中,还是在面试中,web前端性能的优化都是很重要的,那么我们进行优化需要从哪些方面入手呢?可以遵循雅虎的前端优化35条军规,这样对于优化有一个比较清晰的方向.35条军规1.尽量减少HTTP请求个数——须权衡2.使用CDN(内容分发网络)3.为文件头指定Expires或CacheControl,使内容具有缓存性。4.避免空的
Wesley13 Wesley13
2年前
Java爬虫之JSoup使用教程
title:Java爬虫之JSoup使用教程date:201812248:00:000800update:201812248:00:000800author:mecover:https://imgblog.csdnimg.cn/20181224144920712(https://www.oschin
Easter79 Easter79
2年前
Twitter的分布式自增ID算法snowflake (Java版)
概述分布式系统中,有一些需要使用全局唯一ID的场景,这种时候为了防止ID冲突可以使用36位的UUID,但是UUID有一些缺点,首先他相对比较长,另外UUID一般是无序的。有些时候我们希望能使用一种简单一些的ID,并且希望ID能够按照时间有序生成。而twitter的snowflake解决了这种需求,最初Twitter把存储系统从MySQL迁移
Stella981 Stella981
2年前
LightningChart.NET创建显示财务数据的2D StockSeries图表
本教程说明了如何从CSV文件加载财务数据并使用LightningChartStockSeries显示它们。股票系列用于以烛台和股票条格式可视化股票交易数据。本教程假定您已在WinForms或WPF应用程序上使用LightningChart创建了新图表。如果没有,请按照我们的简单2D图表创建应用程序。!(https://image.evget.com
Wesley13 Wesley13
2年前
00:Java简单了解
浅谈Java之概述Java是SUN(StanfordUniversityNetwork),斯坦福大学网络公司)1995年推出的一门高级编程语言。Java是一种面向Internet的编程语言。随着Java技术在web方面的不断成熟,已经成为Web应用程序的首选开发语言。Java是简单易学,完全面向对象,安全可靠,与平台无关的编程语言。
Stella981 Stella981
2年前
Django中Admin中的一些参数配置
设置在列表中显示的字段,id为django模型默认的主键list_display('id','name','sex','profession','email','qq','phone','status','create_time')设置在列表可编辑字段list_editable
Wesley13 Wesley13
2年前
Oracle一张表中实现对一个字段不同值和总值的统计(多个count)
需求:统计WAIT\_ORDER表中的工单总数、未处理工单总数、已完成工单总数、未完成工单总数。表结构:为了举例子方便,WAIT\_ORDER表只有两个字段,分别是ID、STATUS,其中STATUS为工单的状态。1表示未处理,2表示已完成,3表示未完成总数。 SQL:  1.SELECT   2