You're having this issue because the default series added to a chart is a bar graph. You will have to remove the bar graph series and replace it with a Point series in order to display your data. See sample code below.
// clear data from the chart
chart.Series.Clear();
// add an x-y series to the chart
var xySeries = new Charting.Series() {
LegendText = "XY Plot",
ChartType = Charting.SeriesChartType.Point,
Color = Color.Brown,
MarkerStyle = Charting.MarkerStyle.Circle,
MarkerSize = 10
};
chart.Series.Add(xySeries);
// put your point on the series
xySeries.Points.AddXY(1, 1);
// set the axis
chart.ChartAreas[0].AxisX.MajorGrid.LineDashStyle = Charting.ChartDashStyle.Dot;
chart.ChartAreas[0].AxisY.MajorGrid.LineDashStyle = Charting.ChartDashStyle.Dot;
This produces the following chart
You will have to add this using
statement to include Charting
in the available namespaces.
using Charting = System.Windows.Forms.DataVisualization.Charting;
To change the labels on the X-Axis, you will have to use the AxisLabel
property of the DataPoint. See sample below:
// put your point on the series
xySeries.Points.AddXY(0, 1);
xySeries.Points[0].AxisLabel = "0"; // <--- SET AXIS LABEL HERE
Doing will 'coerce' the Chart control to display your chosen axis label.