翻譯|使用教程|編輯:楊鵬連|2020-07-29 11:58:28.777|閱讀 214 次
概述:本教程介紹了如何使用兩個BarSeries創(chuàng)建簡單的2D圖表。 BarSeries將數(shù)據(jù)值表示為矩形條,并且可以用于以非常清晰的方式可視化數(shù)據(jù)之間的差異和方差。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
LightningChart.NET完全由GPU加速,并且性能經(jīng)過優(yōu)化,可用于實時顯示海量數(shù)據(jù)-超過10億個數(shù)據(jù)點。 LightningChart包括廣泛的2D,高級3D,Polar,Smith,3D餅/甜甜圈,地理地圖和GIS圖表以及適用于科學(xué),工程,醫(yī)學(xué),航空,貿(mào)易,能源和其他領(lǐng)域的體繪制功能。LightningChart.NET現(xiàn)已加入在線訂購,現(xiàn)在搶購立享優(yōu)惠!立即咨詢>>
本教程介紹了如何使用兩個BarSeries創(chuàng)建簡單的2D圖表。
BarSeries將數(shù)據(jù)值表示為矩形條,并且可以用于以非常清晰的方式可視化數(shù)據(jù)之間的差異和方差。
在本教程中,BarSeries用于表示兩年期間的每月平均溫度。
本教程假定您已在WinForms或WPF應(yīng)用程序上使用LightningChart創(chuàng)建了新圖表。如果沒有,請按照我們的簡單2D圖表創(chuàng)建應(yīng)用程序。
1.創(chuàng)建一個新的BarSeries并為創(chuàng)建的系列添加樣式。
您可以使用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.生成數(shù)據(jù)作為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.創(chuàng)建第二個BarSeries并為創(chuàng)建的系列添加樣式。
// 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.生成另一組數(shù)據(jù)作為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屬性,用于自定義條形圖在圖表上的顯示方式。
7.配置BarSeries的條形視圖布局。
// Configure bar view layout. chart.ViewXY.BarViewOptions.Grouping = BarsGrouping.ByLocation;LightningChart提供了可能性,通過添加自己的自定義蜱作為軸值CustomAxisTicks。
// 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屬性設(shè)置為false并將CustomTicksEnabled屬性設(shè)置為true。
// Disable autoformating of labels. axisX.AutoFormatLabels = false; // Enable CustomAxisTicks. axisX.CustomTicksEnabled = true;
想要購買FusionCharts Suite XT正版授權(quán),或了解更多產(chǎn)品信息請點擊
本站文章除注明轉(zhuǎn)載外,均為本站原創(chuàng)或翻譯。歡迎任何形式的轉(zhuǎn)載,但請務(wù)必注明出處、不得修改原文相關(guān)鏈接,如果存在內(nèi)容上的異議請郵件反饋至chenjj@fc6vip.cn
文章轉(zhuǎn)載自: