Click here to Skip to main content
15,886,578 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
hi i have a table with for example 100 record with : id- name- open_price - close_price low and high price - date and ...
i want draw a candlestick chart with them .
i write this code for get records from my table :

C#
SqlConnection con = new SqlConnection();
            con.ConnectionString = "Data Source=lenovo;Initial Catalog=getinfo;Integrated Security=True";
            con.Open();
            string sqlcmd = "select *  from database  ";
            SqlCommand comm = new SqlCommand(sqlcmd, con);
            SqlDataAdapter sdap = new SqlDataAdapter();
            DataTable dt = new DataTable();
            sdap.SelectCommand = comm;
            sdap.Fill(dt);
            
            for (int t = 0; t < dt.Rows.Count; t++)
            {
                ??????? draw candlestick chart ??????
            }
Posted
Comments
BillWoodruff 21-Dec-14 7:21am    
There is a CandleStick Chart provided by Microsoft in:

Chart Types
Stock Chart
System.Windows.Forms.DataVisualization.Charting
System.Web.UI.DataVisualization.Charting

http://msdn.microsoft.com/en-us/library/dd456671(v=vs.100).aspx
itman2 21-Dec-14 8:58am    
tanks mr BillWoodruff
i am beginner in c# . i can draw line & column charts but i dont know how can i draw candlestick chart.

can you write a simple sample! for it ?





Web? Win? For both there is a Chart control that support all kinds of display...
http://www.microsoft.com/en-us/download/details.aspx?id=14422[^]
https://code.msdn.microsoft.com/Samples-Environments-for-b01e9c61[^]
 
Share this answer
 
this cod can draw candlestick chart ! i did pay 3$ to andrestand it !! :-)

DataSet ds = new DataSet();
         chart1 = new Chart();
         SqlConnection con = new SqlConnection();
         con.ConnectionString = "Data Source=xxxx;Initial Catalog=xxxx;Integrated Security=True";
         con.Open();
         string sql = "Select * from xxxx ";

         SqlCommand cmd = new SqlCommand(sql, con);
         cmd.CommandType = CommandType.Text;

         SqlDataAdapter sa = new SqlDataAdapter();
         sa.SelectCommand = cmd;

         sa.Fill(ds);
         con.Close();
         chart1.Series["Daily"].ChartType = SeriesChartType.Candlestick;
         chart1.DataSource = sa;

         chart1.Series["Daily"].XValueMember = "Date";
         chart1.Series["Daily"].YValueMembers = "ghbishtarin, ghkamtarin, ghopen, ghclose";
         chart1.DataBind();
         chart1.Series["Daily"].BorderColor = System.Drawing.Color.Black;
         chart1.Series["Daily"].Color = System.Drawing.Color.Black;
         chart1.Series["Daily"].CustomProperties = "PriceDownColor=Green, PriceUpColor=Red";
         chart1.Series["Daily"].XValueType = ChartValueType.Date;
         chart1.ChartAreas[0].AxisX.MajorGrid.LineWidth = 0;
         chart1.ChartAreas[0].AxisY.MajorGrid.LineWidth = 0;
         chart1.ChartAreas[0].AxisY.Minimum = 0;
         chart1.ChartAreas[0].AxisY.Maximum = 210;
         chart1.DataManipulator.IsStartFromFirst = true;
 
Share this answer
 
Comments
Member 12408409 28-Mar-16 0:45am    
Hi I have used 2nd solution, but I didn't get proper output. Chart control is blank.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900