public MainWindow() { InitializeComponent(); GridPanel gp = new GridPanel("1", 4, 4, 0, 0); List <KeyValuePair <string, int> > valueList = new List <KeyValuePair <string, int> >(); valueList.Add(new KeyValuePair <string, int>("Developer", 6000000)); 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)); //Setting data for column chart Chart chart = new Chart(); LineSeries lines = new LineSeries(); lines.Title = "Title"; lines.DependentValuePath = "Value"; lines.IndependentValuePath = "Key"; lines.ItemsSource = valueList; chart.Series.Add(lines); //Setting data for line chart gp.Children.Add(chart); grid.Children.Add(gp); // provera API-ja string URL = "https://www.alphavantage.co/query"; string urlParameters = "?function=TIME_SERIES_WEEKLY&symbol=MSFT&apikey=1ST174M77Q7QPYDW"; StockApi api = new StockApi(); }
public async Task refreshTable() { while (true) { StockApi api = new StockApi(); Dictionary <string, dynamic> data = api.getData(this.stockInfo.urlParameters); if (data == null || !data.ContainsKey(this.stockInfo.getTimeSeriesKey())) { MessageBox.Show("Service can not load required data at the moment! Please clear the window and try again!"); return; //continue; } int i = 0; int j = 0; await Dispatcher.BeginInvoke((Action)(() => { DataGrid dg = new DataGrid(); DataTable table = new DataTable("Data history"); DataColumn timeColumn = new DataColumn("time"); table.Columns.Add(timeColumn); foreach (JProperty timeInterval in data[this.stockInfo.getTimeSeriesKey()]) { i++; JToken value = timeInterval.First.First; if (j == 0) { foreach (JToken child in timeInterval.First) { String token = (child.ToString()); String[] tokens = token.Split(':'); String columnValue = tokens[0].TrimStart('\"'); columnValue = columnValue.TrimEnd('\"'); string columnStr = columnValue.Split(' ')[1]; if (!table.Columns.Contains(columnStr)) { DataColumn tempColumn = new DataColumn(columnStr); table.Columns.Add(tempColumn); } //table.Columns.Add(new DataColumn(columnValue.Split(' ')[1])); } } DataRow row = table.NewRow(); foreach (DataColumn column in table.Columns) { if (column == timeColumn) { row[column] = timeInterval.Name.ToString(); } else { row[column] = Convert.ToString(value.First); value = value.Next; } } table.Rows.Add(row); if (i == stockInfo.numOfPoints) { break; } j++; } if (table.HasErrors == true) { MessageBox.Show("error"); } dg.ItemsSource = table.DefaultView; DataGridSettings(dg); if (this.isClearingActive == true) { return; } if (this.Children.Contains(this.dataGrid)) { this.Children.Remove(this.dataGrid); } this.dataGrid = dg; this.Children.Add(this.dataGrid); })); if (this.isClearingActive == true) { this.isClearingActive = false; return; } await Task.Delay(refresh); } }