none
chart tarih zaman problemi RRS feed

Yanıtlar

  • Ornek:

    void Main()
    {
    	List<Veri> veri = new List<Veri>();
    	int yil = 1997;
    	int ay = 1;
    	using (SqlConnection cn = new SqlConnection(@"server=.\SQLExpress;Database=Northwind;Trusted_Connection=yes"))
    	using (SqlCommand cmd = new SqlCommand(@"select 
    		o.orderDate, 
    		sum(UnitPrice * Quantity) as total 
    	from [Order Details] od
    	inner join Orders o on o.OrderId = od.OrderId
    	where year(o.OrderDate) = @yil and month(o.OrderDate) = @ay
    	and DAY(o.OrderDate) < 10
    	group by o.orderDate
    	order by o.orderDate", cn))
    	{
    		cmd.Parameters.Add("@yil", SqlDbType.Int).Value = yil;
    		cmd.Parameters.Add("@ay", SqlDbType.Int).Value = ay;
    		cn.Open();
    		var reader = cmd.ExecuteReader();
    		while (reader.Read())
    		{
    			veri.Add(
    			new Veri
    			{
    				Tarih = (DateTime)reader["orderDate"],
    				Toplam = (decimal)reader["total"]
    			});
    		}
    		cn.Close();
    	}
    	ChartData(veri, "Tarih", "Toplam", SeriesChartType.Line);
    }
    
    private void ChartData(IEnumerable<Veri> data, string xTitle, string yTitle, SeriesChartType type = SeriesChartType.Column)
    {
    	var series = new Series();
    	series.ChartType = type;
    
    	series.Points.DataBind(data, "Tarih", "Toplam", null);
    
    	var area = new ChartArea();
    	area.AxisX.Title = xTitle;
    	area.AxisY.Title = yTitle;
    	var chart = new Chart { Dock = DockStyle.Fill };
    	chart.ChartAreas.Add(area);
    	chart.Series.Add(series);
    	var form = new Form { Height = 600, Width = 800 };
    	form.Controls.Add(chart);
    	form.Show();
    }
    
    public class Veri
    {
    	public DateTime Tarih { get; set; }
    	public decimal Toplam { get; set; }
    }



    How to create a Minimal, Reproducible Example
    The way to Go.
    World's most advanced open source (object-) relational Database.
    Flutter (for mobile, for web & desktop.

    • Yanıt Olarak İşaretleyen symkontrol 2 Nisan 2020 Perşembe 13:48
    2 Nisan 2020 Perşembe 12:27
    Yanıtlayıcı