Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
335
Using NumericXAxis
posted

Hi,

I would like to use the NumericXAxis in my application. Hence it should be a very simple chart with double values at X and Y axes. I try to modifiy an infragisticy example which use CategoryXAxis and I want to change this in a NumericXAxis. Here is my xaml code:

<Window x:Class="IgSimpleChart.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:ig="http://schemas.infragistics.com/xaml"
        xmlns:local="clr-namespace:IgSimpleChart"
        Title="MainWindow" Height="350" Width="525">
    <Grid>
        
        <Grid.DataContext>
            <local:DataPointCollection />
        </Grid.DataContext>
        
        <ig:XamDataChart x:Name="xmPreviewDataChart" DefaultInteraction="None" IsDragCrosshairEnabled="True">
            <ig:XamDataChart.Axes>
                <!--<ig:CategoryXAxis x:Name="xmPreviewXAxis" ItemsSource="{Binding}"  Label="{}{X}">
                    <ig:CategoryXAxis.LabelSettings >
                        <ig:AxisLabelSettings Location="OutsideBottom" Extent="35" />
                    </ig:CategoryXAxis.LabelSettings>
                </ig:CategoryXAxis>-->
                <ig:NumericXAxis x:Name="xmPreviewXAxis" >
                            <ig:NumericXAxis.LabelSettings >
                                <ig:AxisLabelSettings Location="OutsideBottom" Extent="25" />
                            </ig:NumericXAxis.LabelSettings>
                        </ig:NumericXAxis>
                <ig:NumericYAxis x:Name="xmPreviewYAxis">
                    <ig:NumericYAxis.LabelSettings >
                        <ig:AxisLabelSettings Location="OutsideLeft" Extent="25" />
                    </ig:NumericYAxis.LabelSettings>
                </ig:NumericYAxis>
            </ig:XamDataChart.Axes>
            <ig:XamDataChart.Series>
                <ig:LineSeries  MarkerType="None"
                                        Thickness="2"
                                        ValueMemberPath="Y"
                                        ItemsSource="{Binding}"
                                        XAxis="{Binding ElementName=xmPreviewXAxis}"
                                        YAxis="{Binding ElementName=xmPreviewYAxis}">
                </ig:LineSeries>
            </ig:XamDataChart.Series>
        </ig:XamDataChart >
    </Grid>
</Window>

You see that CategoryXAxis is inactive (marked as a comment). How can I "bind" the NumericXAxis to the real data (= DataPointCollection)?

The DataPointCollection looks as follow:

using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace IgSimpleChart
{
    public class DataPointCollection : ObservableCollection<DataPoint>
    {
        public DataPointCollection()
        {
            int cnt = 4000;

            var rnd = new Random(0);

            for (int x = 0; x < cnt; x++)
            {
                double f = (double)rnd.Next(0, 10) / (double)100.0;

                double y = Math.Sin(x / (0.25 * cnt) + f);

                this.Add(new DataPoint() { X = x, Y = y });
            }
        }
    }

    public class DataPoint
    {
        public double X { get; set; }
        public double Y { get; set; }
    }
}

Kind Regards,

Thomas

Parents Reply Children
No Data