X & Y графики Livechart c# wpf - PullRequest
       48

X & Y графики Livechart c# wpf

1 голос
/ 16 апреля 2020

Я пытаюсь создать XY диаграмму с графиками, из db я беру 2 столбца со значениями, но я не могу создать ось X. Я прочитал этот вопрос LiveCharts - построение x & y из списков , но я не понимаю, где я могу использовать эти ответы

    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
            OleDbConnection connection = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\access.mdb;");
            connection.Open();
            OleDbDataAdapter da = new OleDbDataAdapter("select of_price, duration from bonds", connection);
            OleDbCommandBuilder cb = new OleDbCommandBuilder(da);
            DataSet ds = new DataSet();
            da.Fill(ds, "bonds");
            BondGrid.ItemsSource = ds.Tables["bonds"].DefaultView;
            connection.Close();

            List<double> last_price_list = new List<double>();
            List<double> duration = new List<double>();
            using (connection)
            {
                connection.Open();
                using (OleDbCommand command = new OleDbCommand("select of_price, duration from bonds", connection))
                {
                    using (OleDbDataReader reader = command.ExecuteReader())
                    {
                        if (reader != null)
                        {
                            while (reader.Read())
                            {
                                last_price_list.Add(Convert.ToDouble(reader["of_price"]));
                                duration.Add(Convert.ToDouble(reader["duration"]));
                            }
                        }
                    }
                }
            }
            SeriesCollection = new SeriesCollection
            {                
                new LineSeries
                {
                    Title = "Series 1",
                    Values = new ChartValues<double>(last_price_list)                    
                },               
            };
            YFormatter = value => value.ToString("C");
            SeriesCollection[1].Values.Add(5d);
            DataContext = this;
        }
        public SeriesCollection SeriesCollection { get; set; }
    }
...