使用ZedGraph记录(原创)

我在vs2003中,要画股票K线图以及饼图

在网上找了半天,终于确定一个工具……ZedGraph

 先在添加引用,选择ZedGraph.dll

然后在工具箱中添加ZedGraph控件

将控件拖到页面上

然后在控件的RenderGraph事件中插入代码

饼图代码:

 

 

  

ContractedBlock.gif ExpandedBlockStart.gif Code
                        GraphPane myPane =  (GraphPane)pane[0];
            DataTable dt 
= ssih.GetList("1=1 order by 表A desc");
            
double tag1 = 0;//看长
            double tag2= 0;//看中
            double tag3= 0;//看多
            int j=0;
            
foreach(DataRow dr in dt.Rows)
ExpandedBlockStart.gifContractedBlock.gif            
{
                
if(j==0)
ExpandedSubBlockStart.gifContractedSubBlock.gif                
{
                    tag1 
= Convert.ToDouble(dr["看长"].ToString())*100;
                    tag2 
= Convert.ToDouble(dr["看中"].ToString())*100;
                    tag3 
= Convert.ToDouble(dr["看多"].ToString())*100;
                }

                j
++;
            }

                        
//标题粗体
            myPane.Title.FontSpec.IsItalic = true;
                        
//背景
            myPane.Fill = new Fill( Color.White, Color.White, 45.0f );
            myPane.Chart.Fill.Type 
= FillType.None;
                        
//说明文字位置定义
//            myPane.Legend.Position = LegendPos.Float;
            myPane.Legend.Location = new Location( 0.5f0.6f, CoordType.PaneFraction,
                AlignH.Right, AlignV.Top );
            myPane.Legend.IsVisible 
= false;
            myPane.Legend.FontSpec.Size 
=25f;
            myPane.Legend.IsHStack 
= false;
//            PieItem segment1 = myPane.AddPieSlice( tag1, Color.Red, Color.White, 45.0f, 0, "看多" +tag1.ToString("0.##")+"%" );
//            PieItem segment3 = myPane.AddPieSlice( tag2, Color.White, Color.White, 45.0f, 0, "看平" +tag2.ToString("0.##")+"%" );
//            PieItem segment4 = myPane.AddPieSlice( tag3, Color.Blue, Color.White, 45.0f,  0, "看空" +tag3.ToString("0.##")+"%" );

 

 

 

折线图及股票上证指数的K线图

 

ContractedBlock.gif ExpandedBlockStart.gif Code
                        //上证指数k线图
            DataTable dt = ssih.GetList("1=1 order by dataDate asc");
            
double[] x = new double[dt.Rows.Count +1];
            
double[] y1 = new double[dt.Rows.Count +1];
            
double[] y2 = new double[dt.Rows.Count +1];
            PointPairList pp1 
= new PointPairList();
        
            
int minCount = Convert.ToInt32( dt.Rows.Count - 80);
            
            
for(int m=0;m<minCount;m++)
ExpandedBlockStart.gifContractedBlock.gif            
{
                dt.Rows.Remove(dt.Rows[
0]);
            }



            
int i = 0;
            
foreach(DataRow dr in dt.Rows)
ExpandedBlockStart.gifContractedBlock.gif            
{
                y1[i] 
= Convert.ToDouble(dr["dxyc1"].ToString())*100;
                x[i] 
=new XDate(Convert.ToDateTime(dr["dataDate"]));
                pp1.Add(x[i],y1[i]);
                i
++;
            }


            GraphPane myPane 
= (GraphPane)pane[0];
            myPane.XAxis.Type 
= AxisType.Date;
            myPane.XAxis.Scale.Format 
= "MM-dd";
            myPane.Legend.FontSpec.Size 
=18f;
            myPane.XAxis.Type 
= AxisType.DateAsOrdinal;
            myPane.Legend.Position 
= LegendPos.InsideTopRight;
            myPane.Legend.Location 
= new Location( 0.5f0.6f, CoordType.PaneFraction,
                AlignH.Right, AlignV.Top );
            LineItem myCurve1 
= myPane.AddCurve("看多",pp1, Color.Red, SymbolType.Diamond);
        
            myPane.AxisChange();

 

 

 

ContractedBlock.gif ExpandedBlockStart.gif Code

            DataTable dt 
= ssih.GetList("1=1 order by dataDate asc");
            
double[] x = new double[dt.Rows.Count +1];
            
double[] y1 = new double[dt.Rows.Count +1];
            
double[] y2 = new double[dt.Rows.Count +1];
            
double[] y3 = new double[dt.Rows.Count +1];
            
double[] y4 = new double[dt.Rows.Count +1];
            
double[] y5 = new double[dt.Rows.Count +1];
            
double[] y6 = new double[dt.Rows.Count +1];
            XDate[] x1 
= new XDate[dt.Rows.Count +1];
            PointPairList pp1 
= new PointPairList();
            PointPairList pp2 
= new PointPairList();
            PointPairList pp3 
= new PointPairList();
            PointPairList pp4 
= new PointPairList();
            PointPairList pp5 
= new PointPairList();
            PointPairList pp6 
= new PointPairList();
            PointPairList pp7 
= new PointPairList();


            
int minCount = Convert.ToInt32( dt.Rows.Count - 80);
            
            
for(int m=0;m<minCount;m++)
            {
                dt.Rows.Remove(dt.Rows[
0]);
            }
            
int i = 0;

            
foreach(DataRow dr in dt.Rows)
            {
                
                y1[i] 
= Convert.ToDouble(dr["tag1"].ToString())*100;
                y2[i] 
= Convert.ToDouble(dr["tag2"].ToString())*100;
                y3[i] 
= Convert.ToDouble(dr["tag3"].ToString())*100;
                y4[i] 
= Convert.ToDouble(dr["tag4"].ToString())*100;
                y5[i] 
= Convert.ToDouble(dr["tag5"].ToString())*100;
                y6[i] 
= Convert.ToDouble(dr["tag6"].ToString())*100;
                x[i] 
=new XDate(Convert.ToDateTime(dr["dataDate"]));
                
// Convert.ToDouble( Convert.ToDateTime(dr["dataDate"]).Month + "." + Convert.ToDateTime(dr["dataDate"]).Day)  ;
                pp1.Add(x[i],y1[i]);
                pp2.Add(x[i],y2[i]);
                pp3.Add(x[i],y3[i]);
                pp4.Add(x[i],y4[i]);
                pp5.Add(x[i],y5[i]);
                pp6.Add(x[i],y6[i]);
                
                i
++;
            }
            

            GraphPane myPane 
= (GraphPane)pane[0];
            myPane.XAxis.Type 
= AxisType.Date;
            myPane.XAxis.Scale.Format 
= "MM-dd";
            myPane.XAxis.Type 
= AxisType.DateAsOrdinal;

            myPane.Legend.Position 
=  LegendPos.InsideTopRight;
            myPane.Legend.Location 
= new Location( 0.9f0.6f, CoordType.PaneFraction,
                AlignH.Right, AlignV.Top );

            myPane.Legend.FontSpec.Size 
=14f;
            LineItem myCurve1 
= myPane.AddCurve("熊市",pp1, Color.Green, SymbolType.Diamond);
            LineItem myCurve2 
= myPane.AddCurve("熊市反弹",pp2,  Color.DarkMagenta, SymbolType.Diamond);
            LineItem myCurve3 
= myPane.AddCurve("熊转牛",pp3,  Color.DeepSkyBlue, SymbolType.Diamond);
            LineItem myCurve4 
= myPane.AddCurve("牛调整",pp4,  Color.Thistle, SymbolType.Diamond);
            LineItem myCurve5 
= myPane.AddCurve("牛加速",pp5,  Color.Red, SymbolType.Diamond);
            LineItem myCurve6 
= myPane.AddCurve("牛转熊",pp6,  Color.Chartreuse, SymbolType.Diamond);
    

 

 

 

 

转载于:https://www.cnblogs.com/aaa1028/archive/2009/02/26/1398764.html

你可能感兴趣的:(使用ZedGraph记录(原创))