I am making a currency conversion application with a C# form. I pull the exchange rates with the API, convert them to each other, and add this value to my chart object with two columns, "selling price" and "buying price". My problem is as follows: Whatever value came in the first transaction I opened the program and made, whatever the value is in other transactions, the initial value appears again. For example, let's say I converted 1 USD to JPY, and it gave the value 135. On the left of the chart, 135 appears as the peak value. But then let's say I converted 2 USD to JPY, and the result was 270. But the peak value does not change to 270 and remains at 135. I tried the chart1.height property like this:
chart1.Series.Clear();
chart1.Series.Add($"{a} {neyden} / {neye}");
double bidPriceVal = Convert.ToDouble(bidPrice) * a;
chart1.Series[$"{a} {neyden} / {neye}"].Points.AddXY("Teklif Fiyatı", bidPriceVal);
double askPriceVal = Convert.ToDouble(askPrice) * a;
double askPriceValint = Convert.ToInt32(askPriceVal);
askPriceValint = chart1.Height;
chart1.Series[$"{a} {neyden} / {neye}"].Points.AddXY("Alış Fiyatı", askPriceVal);
But still didn't work. And that's the rest of the code:
private void button1_Click_1(object sender, EventArgs e)
{
Random x = new Random();
api = ApiKey[x.Next(ApiKey.Count)];
if (comboBox1.SelectedItem == null)
{
if (label3.Text == tr)
{
MessageBox.Show("Lütfen önce dönüştürmek istediğiniz değerleri girin.");
}
else if (label3.Text == eng)
{
MessageBox.Show("Please enter the values you want to convert first.");
}
}
else
{
string neyden = comboBox1.SelectedItem.ToString();
string neye = comboBox2.SelectedItem.ToString();
string url = $"https://www.alphavantage.co/query?function=CURRENCY_EXCHANGE_RATE&from_currency={neyden}&to_currency={neye}&apikey={api}";
string data = "";
double donusumMiktari;
try
{
if (string.IsNullOrWhiteSpace(textBox1.Text))
{
donusumMiktari = 1;
textBox1.Text = "1";
}
else
{
donusumMiktari = Convert.ToDouble(textBox1.Text);
a = Convert.ToDouble(donusumMiktari);
}
}
catch (Exception)
{
if (label3.Text == tr)
{
MessageBox.Show("Geçersiz bir karakter girdiğiniz için tutar" + " 1 " + "olarak ayarlanmıştır. Lütfen sadece sayı girin");
}
else if (label3.Text == eng)
{
MessageBox.Show("The amount is set to" + " 1 " + "because you entered an invalid character. Please enter only number");
}
}
using (WebClient client = new WebClient())
{
data = client.DownloadString(url);
}
JObject json = JObject.Parse(data);
var exchangeRate = json["Realtime Currency Exchange Rate"];
if (exchangeRate != null)
{
var rate = exchangeRate["5. Exchange Rate"];
var lastRefreshed = exchangeRate["6. Last Refreshed"];
var bidPrice = exchangeRate["8. Bid Price"];
var askPrice = exchangeRate["9. Ask Price"];
if (rate != null && lastRefreshed != null && bidPrice != null && askPrice != null)
{
dataGridView1.Rows.Add(neyden, neye, (Convert.ToDouble(rate) * a).ToString().Substring(0, 5), lastRefreshed.ToString(), (Convert.ToDouble(bidPrice) * a).ToString(), (Convert.ToDouble(askPrice) * a).ToString());
chart1.Series.Clear();
chart1.Series.Add($"{a} {neyden} / {neye}");
double bidPriceVal = Convert.ToDouble(bidPrice) * a;
chart1.Series[$"{a} {neyden} / {neye}"].Points.AddXY("Teklif Fiyatı", bidPriceVal);
double askPriceVal = Convert.ToDouble(askPrice) * a;
double askPriceValint = Convert.ToInt32(askPriceVal);
askPriceValint = chart1.ChartAreas[0].AxisY.Maximum;
chart1.Series[$"{a} {neyden} / {neye}"].Points.AddXY("Alış Fiyatı", askPriceVal);
}
else
{
if (label3.Text == tr)
{
MessageBox.Show("Kur bilgisi alınamadı! Bir süre sonra tekrar deneyin.");
}
else if (label3.Text == eng)
{
MessageBox.Show("Could not get exchange rate information! Try again after a while.");
}
}
}
else
{
if (label3.Text == tr)
{
MessageBox.Show("Kur bilgisi alınamadı! Bir süre sonra tekrar deneyin.");
}
else if (label3.Text == eng)
{
MessageBox.Show("Could not get exchange rate information! Try again after a while.");
}
}
}
}