2015-04-16 95 views
2

我試圖用zed圖創建折線圖。我只想問如何創建一個線圖,其中XAxis類型是文本,YAxis類型是雙倍。ZedGraph如何使用XAxis.Type = AxisType.Text創建經典折線圖

首先,我真的在搜索這個主題,但我沒有得到任何有關它的結果。因爲其他線圖總是關於XAxis上的日期&時間。我不需要XAxis上的日期&。我將使用XAxis的標籤來命名YAxis上的點。

Here an Example Graph

  string[] labels = { "P(A)", "P(A)+P(T)", "P(A)+P(T)+P(G)", "P(A)+P(T)+P(G)+P(C)" }; 
    double[] y = { PA(), PA() + PT(), PA() + PT() + PG(), PA() + PT() + PG() + PC() }; 

    LineItem myLine = myPane.AddCurve("dizi 1", null, y, Color.Red); 
    myLine.Line.Fill = new Fill(Color.Red, Color.White, Color.Red); 

    myPane.XAxis.Scale.TextLabels = labels; 
    myPane.XAxis.Type = AxisType.Text; 

    myPane.Chart.Fill = new Fill(Color.White, Color.FromArgb(255, 255, 166), 90F); 
    myPane.Fill = new Fill(Color.FromArgb(250, 250, 255)); 
    zedGraphControl1.AxisChange(); 

****代碼是上方。有什麼不對嗎?****

回答

2

我只是想通了!

以下是創建基本線圖的示例代碼!

 private void button3_Click(object sender, EventArgs e) 
    { 
     // generate some fake data 
     double[] y = { 1, 2, 3, 9 ,1,15,3,7,2}; 
     string[] schools = { "A", "B", "C", "D" ,"E","F","G","H","J"}; 

     //generate pane 
     var pane = zg1.GraphPane; 


     pane.XAxis.Scale.IsVisible = true; 
     pane.YAxis.Scale.IsVisible = true; 

     pane.XAxis.MajorGrid.IsVisible = true; 
     pane.YAxis.MajorGrid.IsVisible = true; 

     pane.XAxis.Scale.TextLabels = schools; 
     pane.XAxis.Type = AxisType.Text; 


     //var pointsCurve; 

     LineItem pointsCurve = pane.AddCurve("", null, y, Color.Black); 
     pointsCurve.Line.IsVisible = true; 
     pointsCurve.Line.Width = 3.0F; 
     //Create your own scale of colors. 

     pointsCurve.Symbol.Fill = new Fill(new Color[] { Color.Blue, Color.Green, Color.Red }); 
     pointsCurve.Symbol.Fill.Type = FillType.Solid; 
     pointsCurve.Symbol.Type = SymbolType.Circle; 
     pointsCurve.Symbol.Border.IsVisible = true; 



     pane.AxisChange(); 
     zg1.Refresh(); 
     this.Controls.Add(zg1); 
    }