Search code examples
c#sqlplotzedgraph

zed graph: how to make my graph start at 0,0


I want my graph to start at 0,0 but right now it is starting at the time that the data starts (because i don't know what a better alternative for xdatamember would be to get my desired results. any suggestions?

        private void Form1_Load(object sender, EventArgs e)
        {
        dataAdapter = new SqlDataAdapter(strSQL, strCon);
        commandBuilder = new SqlCommandBuilder(dataAdapter);

        // Populate a new data table and bind it to the BindingSource.
        DataTable table = new DataTable();
        table.Locale = System.Globalization.CultureInfo.InvariantCulture;
        dataAdapter.Fill(table);
        bindingSource.DataSource = table;

        // Resize the DataGridView columns to fit the newly loaded content.
        dataGridView.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCellsExceptHeader);
        // you can make it grid readonly.
        dataGridView.ReadOnly = true;
        // finally bind the data to the grid
        dataGridView.DataSource = bindingSource;
        GraphPane myPane = height.GraphPane;

        // Create a new DataSourcePointList to handle the database connection
        DataSourcePointList dspl = new DataSourcePointList();

        // Specify the table as the data source
        dspl.DataSource = table;

        dspl.XDataMember = "age";
        dspl.YDataMember = "height";

        LineItem Curve1 = myPane.AddCurve("student 1", dspl, Color.pink, SymbolType.None);
        height.AxisChange();
        myPane.Chart.Fill = new Fill(Color.White, Color.LightGray, 45.0F);

        // set the title and axis labels
        myPane.Title.Text = "student heights";
        myPane.XAxis.Title.Text = "age";
        myPane.YAxis.Title.Text = "height";

        myPane.XAxis.Type = AxisType.Date;
    }

Solution

  • First, I did a quick search for this sort of thing and found this: Lock axis in ZedGraph

    You can set the XAxis.Min and YAxis.Min to whichevers value you want shown as the min of the respective Axes. My code from my test looked like this:

    //static ZedGraph.ZedGraphControl graph = new ZedGraph.ZedGraphControl();
    ZedGraph.GraphPane pane = graph.GraphPane;
    pane.XAxis.Scale.Min = 0.0;
    graph.AxisChange();
    graph.RestoreScale(pane);
    graph.ZoomOut(pane);