翻譯|其它|編輯:吳園園|2019-08-27 15:59:22.170|閱讀 230 次
概述:本文整理了用戶在使用MindFusion.Charting for WPF常見的問題,希望對您有所幫助。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
MindFusion.Charting for WPF支持所有主流的圖表類型,以及許多自定義的圖表功能。線形圖表控件允許你創(chuàng)建折線圖、面積圖、散點圖或它們之間的任何組合形式。條形圖表控件支持創(chuàng)建集群、堆疊或重疊的條形和柱狀圖。餅圖圖表控件則允許你創(chuàng)建環(huán)形圖表,并且還可對它們的厚度進行自定義調(diào)整。
本文整理了用戶在使用MindFusion.Charting for WPF常見的問題,希望對您有所幫助。
點擊下載MindFusion.Charting for WPF最新試用版
問:我想在圖表軸上顯示DateTime值。我使用數(shù)字作為點,但我不想顯示這些數(shù)據(jù),我想顯示它附帶的DateTime值。這可以用你的工具嗎?
答: Wpf的圖表支持在任何圖表軸上繪制自定義標(biāo)簽。自定義標(biāo)簽既可以在軸的間隔位置繪制,也可以在該軸的數(shù)據(jù)點位置繪制。
在您的情況下,我們假設(shè)您要在軸的數(shù)據(jù)點位置繪制從數(shù)據(jù)源獲取的DateTime標(biāo)簽。這是你的代碼:
//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";
請注意,設(shè)置標(biāo)簽的格式非常重要。如果不這樣做,控件將嘗試使用標(biāo)準(zhǔn)轉(zhuǎn)換將DateTime值轉(zhuǎn)換為字符串,結(jié)果將不會如預(yù)期的那樣。
問:我有8個類別的數(shù)據(jù),每個類別有3個不同的值。我想在堆積圖表中顯示這些類別,每個類別的名稱作為標(biāo)簽但不知道如何操作。
答:您想要顯示的內(nèi)容可以通過在條形圖控件中添加3個BarSeries來完成。然后,您可以將每個系列的XDataPath或YDataPath屬性綁定到數(shù)據(jù)源中的相應(yīng)字段。將條形的類型設(shè)置為堆疊。
以下是構(gòu)建堆積柱形圖的方法:
//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;
這是一個示例列表,其中包含用于綁定圖表的數(shù)據(jù):
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} };
我們分配數(shù)據(jù)源并將X軸的標(biāo)簽類型設(shè)置為自定義文本。該XLabelPath屬性設(shè)置,提供了自定義標(biāo)簽的字段的名稱:
barChart1.DataSource = salesList; barChart1.XAxisSettings.LabelType = LabelType.CustomText; barChart1.XLabelPath = "Category";
教程持續(xù)更新中,感興趣的朋友記得持續(xù)關(guān)注后續(xù)教程~
相關(guān)推薦:
MindFusion.Diagramming for WinForms常見問題集錦
MindFusion.Diagramming for Java問題集錦
想要購買MindFusion.Charting for WPF 正版授權(quán)的朋友可以。
更多精彩內(nèi)容,歡迎關(guān)注下方的微信公眾號,及時獲取產(chǎn)品最新資訊▼▼▼
本站文章除注明轉(zhuǎn)載外,均為本站原創(chuàng)或翻譯。歡迎任何形式的轉(zhuǎn)載,但請務(wù)必注明出處、不得修改原文相關(guān)鏈接,如果存在內(nèi)容上的異議請郵件反饋至chenjj@fc6vip.cn
文章轉(zhuǎn)載自: