none
WPF中的ChartingToolkit控件,X轴值相同时,怎样控制画点的顺序?? RRS feed

  • 问题

  • 如上图,WPF中的ChartingToolkit控件,绑定的数据源中,如果有X轴的值相同,Y轴的值不同时,

    如果反复绑定该组值,就会遇到上图的现象,X值相同的点,画线的先后顺序不一定。

    有高手知道这是什么问题导致的吗????

    感谢指导~~!!!!!

    2016年10月18日 11:13

全部回复


  • Hi Yuan Lu,

    >>如果反复绑定该组值,就会遇到上图的现象,X值相同的点,画线的先后顺序不一定。

    你可以尝试定义一个KeyValuePair的集合。

    XAML:

    <Grid>
            <ScrollViewer HorizontalScrollBarVisibility="Auto" 
    	VerticalScrollBarVisibility="Auto" >
                <Grid >
                    <chartingToolkit:Chart x:Name="testchart" Height="262" HorizontalAlignment="Left" 
    		Margin="50,0,0,574" Title=" Demo" 
    		VerticalAlignment="Bottom" Width="360">
                        <chartingToolkit:LineSeries DependentValuePath="Value" 
    		IndependentValuePath="Key" ItemsSource="{Binding}" />
                    </chartingToolkit:Chart>
                    <Button Click="Button_Click"  Height="40" Width="60" Margin="200,335,215,461">TEST</Button>
    
                    <Button Click="Button_Click_1"  Height="40" Width="60" Margin="325,335,90,461">Reset</Button>
                </Grid>
                
            </ScrollViewer>
            
        </Grid>

    XAML.CS:

        /// <summary>
        /// Interaction logic for ChartingToolkitWPF.xaml
        /// </summary>
        public partial class ChartingToolkitWPF : Window
        {
            public ObservableCollection<KeyValuePair<string, int>> ValueList;
            public ChartingToolkitWPF()
            {
                InitializeComponent();
    
                this.ValueList = new ObservableCollection<KeyValuePair<string, int>>();
                ValueList.Add(new KeyValuePair<string, int>("Developer", 60));
                ValueList.Add(new KeyValuePair<string, int>("Misc", 20));
                ValueList.Add(new KeyValuePair<string, int>("Tester", 50));
                ValueList.Add(new KeyValuePair<string, int>("QA", 30));
                ValueList.Add(new KeyValuePair<string, int>("Project Manager", 40));
                testchart.DataContext = ValueList;
            }
    
            private void Button_Click(object sender, RoutedEventArgs e)
            {
                for (int i = 0; i < 20; i++)
                {
                    this.ValueList = new ObservableCollection<KeyValuePair<string, int>>();
                    ValueList.Add(new KeyValuePair<string, int>("Developer", 60 ));
                    ValueList.Add(new KeyValuePair<string, int>("Misc", 20+i));
                    ValueList.Add(new KeyValuePair<string, int>("Tester", 50 ));
                    ValueList.Add(new KeyValuePair<string, int>("QA", 30 + i));
                    ValueList.Add(new KeyValuePair<string, int>("Project Manager", 40 + i));
                    testchart.DataContext = ValueList;
                }
            }
    
            private void Button_Click_1(object sender, RoutedEventArgs e)
            {
                this.ValueList = new ObservableCollection<KeyValuePair<string, int>>();
                ValueList.Add(new KeyValuePair<string, int>("Developer", 60));
                ValueList.Add(new KeyValuePair<string, int>("Misc", 20));
                ValueList.Add(new KeyValuePair<string, int>("Tester", 50));
                ValueList.Add(new KeyValuePair<string, int>("QA", 30));
                ValueList.Add(new KeyValuePair<string, int>("Project Manager", 40));
                testchart.DataContext = ValueList;
            }
        }
    

    Best Regards,

    Yohann Lu


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    2016年10月21日 8:40
    版主
  • Hi Yohann Lu~

    首先非常感谢您的帮助~!!!!^_^

    我用的是KeyValuePair集合,

    您的例子中没有X轴相同的数据

    this.ValueList = new ObservableCollection<KeyValuePair<string, int>>();
               
    ValueList.Add(new KeyValuePair<string, int>("Developer", 60));
               
    ValueList.Add(new KeyValuePair<string, int>("Misc", 20));
               
    ValueList.Add(new KeyValuePair<string, int>("Misc", 50));
               
    ValueList.Add(new KeyValuePair<string, int>("QA", 30));
               
    ValueList.Add(new KeyValuePair<string, int>("Project Manager", 40));
                testchart
    .DataContext = ValueList;

    您用上面这组数据反复切换试试,就会出现不同的折线图。

    祝顺利~!

    Yuan lu

    2016年10月24日 6:28