C# zed graph:如何使我的图形从0,0开始
我希望我的图表从0,0开始,但现在它是从数据开始的时候开始的(因为我不知道xdatamember有什么更好的选择可以得到我想要的结果。有什么建议吗C# zed graph:如何使我的图形从0,0开始,c#,sql,plot,zedgraph,C#,Sql,Plot,Zedgraph,我希望我的图表从0,0开始,但现在它是从数据开始的时候开始的(因为我不知道xdatamember有什么更好的选择可以得到我想要的结果。有什么建议吗 private void Form1_Load(object sender, EventArgs e) { dataAdapter = new SqlDataAdapter(strSQL, strCon); commandBuilder = new SqlCommandBuilder(d
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;
}
首先,我快速搜索了这类东西,发现: 您可以将XAxis.Min和YAxis.Min设置为希望显示为各自轴的Min的值。我的测试代码如下所示:
//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);
回答得好。只想补充一点,在正常情况下,特别是在初始化阶段,设置轴
Scale.Min=0.0
和pane.AxisChange()
或graph.AxisChange()
就足够了;RestoreScale
和ZoomOut
是多余的(至少在初始设置中)。