سؤال

Please tell me if I am missing some settings that I need to set. As in my graph I am getting column values in my x asis and not 0 1 2 3 4 5 6 7 8 9

    private void button2_Click(object sender, EventArgs e)
    {       

        chart1.DataSource = csvData;
        chart1.ChartAreas[0].AxisX.Minimum = 0;
        chart1.ChartAreas[0].AxisX.Maximum = 10;
        chart1.ChartAreas[0].AxisX.Minimum = -5;
        chart1.ChartAreas[0].AxisX.Maximum = 5;

        chart1.Series["Series2"].YValueMembers = "Column name";
        chart1.Series["Series2"].XValueMember = "Column name";
        chart1.DataBind();

    }




}
}
هل كانت مفيدة؟

المحلول 2

private void button2_Click(object sender, EventArgs e) {

    DataTable dtCloned = csvData.Clone();
    dtCloned.Columns["column name"].DataType = typeof(double);
    dtCloned.Columns["column name"].DataType = typeof(double);

    chart1.DataSource = dtCloned;
    chart1.ChartAreas[0].AxisX.Minimum = 0;
    chart1.ChartAreas[0].AxisX.Maximum = 10;
    chart1.ChartAreas[0].AxisX.Minimum = -5;
    chart1.ChartAreas[0].AxisX.Maximum = 5;

    chart1.Series["Series2"].YValueMembers = "Delta_Sigma";
    chart1.Series["Series2"].XValueMember = "CpK_Refrence";
    chart1.DataBind();

}

نصائح أخرى

Ah ok I understand your issue now. The issue is that when you are reading the data from the csv it is adding all the data as string and the chart is then reading the values as string thats why none of the Chart1.ChartAreas(0).AxisX.Maximum = 10 changes the axis.

You need to change how the data is read from the csv. In essence you need to add

csvData.Columns["CpK_Refrence"].DataType = GetType(Integer)

before any data is added to the datatable [you cannot change a column type once data has been added]. if all your columns are going to numbers then change the below so all your columns are numeric columns

DataColumn datecolumn = new DataColumn(column);
'TO
DataColumn datecolumn = new DataColumn("Column1", typeof(double));
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top