Csharp/C#教程:WPF工具包图表中的X轴刻度标记分享


WPF工具包图表中的X轴刻度标记

            

 using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Shapes; using System.Windows.Controls.DataVisualization.Charting; namespace tradtest { ///  /// Interaction logic for chart.xaml ///  public partial class chart : Window { void AddSeries(string title, KeyValuePair[] data, SolidColorBrush linecolor) { LineSeries ls = new LineSeries(); ls.DependentValuePath = "Value"; ls.IndependentValuePath = "Key"; ls.ItemsSource = data; ls.Title = title; Style dpstyle = ls.DataPointStyle; //Style tmp1 = this.Resources["SimpleLineSeriesStyle"] as Style; Style tmp1 = new Style(); tmp1.Setters.Add(new Setter(LineDataPoint.BackgroundProperty, linecolor)); tmp1.Setters.Add(new Setter(LineDataPoint.WidthProperty, 0.0)); tmp1.Setters.Add(new Setter(LineDataPoint.HeightProperty, 0.0)); //wi //dpstyle = tmp1; ls.DataPointStyle = tmp1; //SetterBaseCollection sr = dpstyle.Setters; //SetterBase sb = new Setter(Background, (object)Brushes.AliceBlue); chart1.Series.Add(ls); } public chart(KeyValuePair[] spreadseries, KeyValuePair[] meanspreadseries, KeyValuePair[] enterlongseries, KeyValuePair[] entershortseries, KeyValuePair[] exitlongseries, KeyValuePair[] exitshortseries) { InitializeComponent(); chart1.Series.Clear(); AddSeries("Current Spread", spreadseries, Brushes.MediumPurple); AddSeries("Mean Spread", meanspreadseries, Brushes.Black); AddSeries("Enter Long Spread", enterlongseries, Brushes.Red); AddSeries("Enter Short Spread", entershortseries, Brushes.Red); AddSeries("Exit Long Spread", exitlongseries, Brushes.Orange); AddSeries("Exit Short Spread", exitshortseries, Brushes.Orange); } } } 

我上面附上了我的代码。 我无法删除X轴刻度线。 有人可以请教吗?

您可以像这样隐藏整个X轴:

    

将其添加到您的charting:LineSeries元素或代码中:

 series.IndependentAxis = new CategoryAxis { Orientation = AxisOrientation.X, Visibility = Visibility.Collapsed }; 

所有系列都共享相同的X轴吗? 因此,您可以添加通用X轴(如果使用字符串独立值,则建议的类别更好)并设置AxisLabelStyle以显示内容模板的内容样式。 我使用此解决方案,系列添加运行时将使用您添加的现有X轴。

HTH

上述就是C#学习教程:WPF工具包图表中的X轴刻度标记分享的全部内容,如果对大家有所用处且需要了解更多关于C#学习教程,希望大家多多关注—计算机技术网(www.ctvol.com)!

本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。

ctvol管理联系方式QQ:251552304

本文章地址:https://www.ctvol.com/cdevelopment/950850.html

(0)
上一篇 2021年11月17日
下一篇 2021年11月17日

精彩推荐