Click here to Skip to main content
15,888,293 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I'm trying to create a Line Graph with zed graph. I just wanted to ask that how can I create a Line Graph which XAxis type is text and YAxis type is doubles.

Firstly i was really searching about this topic but i didnt get any result about it. Because other Line graphs are always about date&time on XAxis. I don't need date&time on XAxis. I will use labels for XAxis to name points on YAxis .

Here is an Example Graph


I want to create a graph like above.

Codes i've been trying belove :

C#
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();


Thank you!
Posted

1 solution

I just figured it out !

Here is an basic example about creating a line graph with ZedGraph

C#
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);
}
 
Share this answer
 

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