Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
45
Line chart data not aligning to x axis labels
posted

Why does the line chart not align to the labels on the x-axis? I am using a subset of infragistics sample data to display the problem.

To recreate, create a simple project that has one Form. On the form, Add a winchart. Set the ChartType to LineChart. Switch to code view. Copy and paste and below card. Compile and run. I have played around with a great many of the Axis and Label appearance but nothing seems to work.

Any help will be greatly appreciated.


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace SimpleLineChart
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private DataTable GenerateData()
        {
            DataTable dt = new DataTable();
            dt.Columns.Add("StockName", typeof(string));
            dt.Columns.Add("Monday", typeof(double));
            dt.Columns.Add("Tuesday", typeof(double));

            DataRow row1 = dt.NewRow();
            row1.ItemArray = new object[ { "IBM", 111, 96 };

            DataRow row2 = dt.NewRow();
            row2.ItemArray = new object[ { "MSN", 75, 23 };

            DataRow row3 = dt.NewRow();
            row3.ItemArray = new object[ { "MCI", 55, 63 };

            dt.Rows.Add(row1);
            dt.Rows.Add(row2);
            dt.Rows.Add(row3);

            return dt;
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            _lineChart.DataSource = GenerateData();
            _lineChart.DataBind();
        }
    }
}