使用Livecharts Constant Changes示例希望将不同类的double变量赋值给ConstantChangesChart()的Value Variable

时间:2017-06-27 09:52:19

标签: c# livecharts

我希望此变量名称压力分配给可衡量类的值变量。

public static float[] Pressure1 = new float[35000];


constantChangesChart CLass();

           public partial class ConstantChangesChart : UserControl,        
                                            INotifyPropertyChanged
         {
              private double _axisMax;
              private double _axisMin;
              private double _trend;
              double []cv=new double[]{1.2,3,4,5,2,6,7,8,9,0,1,1};

        public ConstantChangesChart()
        {
            InitializeComponent();

            //To handle live data easily, in this case we built a specialized type
            //the MeasureModel class, it only contains 2 properties
            //DateTime and Value
            //We need to configure LiveCharts to handle MeasureModel class
            //The next code configures MeasureModel  globally, this means
            //that LiveCharts learns to plot MeasureModel and will use this config every time
            //a IChartValues instance uses this type.
            //this code ideally should only run once
            //you can configure series in many ways, learn more at 

            //http://lvcharts.net/App/examples/v1/wpf/Types%20and%20Configuration

            var mapper = Mappers.Xy<MeasureModel>()
                .X(model => model.DateTime.Ticks)   //use DateTime.Ticks as X
                .Y(model => model.Value);           //use the value property as Y
               // .Y(model => model.Value2);

            //lets save the mapper globally.
            Charting.For<MeasureModel>(mapper);
            // Charting.For<Double>(mapper);
            //the values property will store our values array
            ChartValues = new ChartValues<MeasureModel>();
          //  ChartVal = new ChartValues<double>();
            //lets set how to display the X Labels
            DateTimeFormatter = value => new DateTime((long) value).ToString("mm:ss");
            //cv[5]=1.2;

            //AxisStep forces the distance between each separator in the X axis
            AxisStep = TimeSpan.FromSeconds(1).Ticks;
            //AxisUnit forces lets the axis know that we are plotting seconds
            //this is not always necessary, but it can prevent wrong labeling
            AxisUnit = TimeSpan.TicksPerSecond;

            SetAxisLimits(DateTime.Now);

            //The next code simulates data changes every 300 ms

            IsReading = false;

            DataContext = this;
        }

        public ChartValues<MeasureModel> ChartValues { get; set; }

        public Func<double, string> DateTimeFormatter { get; set; }
        public double AxisStep { get; set; }
        public double AxisUnit { get; set; }
        public static float[] Pressure1 = new float[35000];
        public double AxisMax
        {
            get { return _axisMax; }
            set
            {
                _axisMax = value;
                OnPropertyChanged("AxisMax");
            }
        }
        public double AxisMin
        {
            get { return _axisMin; }
            set
            {
                _axisMin = value;
                OnPropertyChanged("AxisMin");
            }
        }

        public bool IsReading { get; set; }



        private void Read()
        {
            var r = new Random();

            while (IsReading)
            {

                Thread.Sleep(150);
                var now = DateTime.Now;



                _trend += r.Next(0, 10);


                ChartValues.Add(new MeasureModel
                {

                    DateTime = now,
                    Value = _trend,
                   // Value2=
                    Value 2=Pressure1;

                });

但我被困在其中。

我的另一个类,我将来自串口的数据存储到几乎1024字节的压力变量值。

               for (int i = 0; i < 1024; i++)
                {
                    if (gsb_read_block <= (gsb_no_of_blocks/2))
                    {
                        TempVal = (Int16)(response[x++] << 8);
                        TempVal |= response[x++];


                        TempValFloat = (float)((TempVal * 1.00f) / 100.0f);
                        Pressure1[(i + ((gsb_read_block - 1) * 1024))] = (float)Convert.ToDouble(TempValFloat.ToString("F2"));

                        //Pressure1[(i+((gsb_read_block-1)*1024))] =(UInt16) TempVal;
                    }
                    else
                    {
                        TempVal = (Int16)(response[x++] << 8);
                        TempVal |= response[x++];

                        TempValFloat = (float)((TempVal * 1.00f) / 100.0f);
                        Pressure2[(i + (((UInt16)(gsb_read_block / 2) - 1) * 1024))] = (float)Convert.ToDouble(TempValFloat.ToString("F2"));
                        //Pressure2[(i + (((UInt16)(gsb_read_block/2) - 1) * 1024))] = (UInt16)TempVal;
                    }

所以我想将压力值表示为图表的y轴相对于X轴上的时间。

0 个答案:

没有答案