Jump to content
Software FX Community

Bar chart location doesn't match up X-Axis(DateTime)


Recommended Posts


I'm trying to show some event with bar chart.


[Im trying to]

X-Axis format is DateTime.

Each bar is a event that occured at bar's X-Axis time.

Each series is a event's type (there is many series)


But bar's x-axis location doesn't match up it's x-value.


[for example]

In Code: chart.Data.X[0.0] = Convert.ToString("2020-05-20 16:00:00").ToOADate();

In Chart: bar's x-axis location looks like "2020-05-15 02:00:00";

All bar's locations seems to be moved to right;


how can I solve this problem?

help me please.


Link to comment
Share on other sites

Can you please post some sample data along with an image of the chart you would want to create for such data?

In our product some gallery types (like Scatter, Line, Area) support arbitrary X values while others (like Bar) do not as it would cause Bars to be overlapped or not have the same width.



Link to comment
Share on other sites

Because of company policy of Information Security, I can't append a Image File.

But I could post sample code that I'd tried to.


Here is code (I want for bar to be located exactly what bar's x-value points):


public Form1()
            DataTable valueDT = new DataTable();
            valueDT.Columns.Add("time", typeof(DateTime));
            valueDT.Columns.Add("value", typeof(int));
            valueDT.Rows.Add(Convert.ToDateTime("2020-05-21 01:00:00"), 1);
            valueDT.Rows.Add(Convert.ToDateTime("2020-05-21 02:00:00"), 2);
            valueDT.Rows.Add(Convert.ToDateTime("2020-05-21 03:00:00"), 6);
            valueDT.Rows.Add(Convert.ToDateTime("2020-05-21 04:00:00"), 4);
            valueDT.Rows.Add(Convert.ToDateTime("2020-05-21 05:00:00"), 2);
            valueDT.Rows.Add(Convert.ToDateTime("2020-05-21 06:00:00"), 3);

            DataTable eventDT = new DataTable();
            eventDT.Columns.Add("time", typeof(DateTime));
            eventDT.Rows.Add(Convert.ToDateTime("2020-05-21 01:00:00"));
            eventDT.Rows.Add(Convert.ToDateTime("2020-05-21 02:00:00"));
            eventDT.Rows.Add(Convert.ToDateTime("2020-05-21 03:00:00"));
            eventDT.Rows.Add(Convert.ToDateTime("2020-05-21 04:00:00"));
            eventDT.Rows.Add(Convert.ToDateTime("2020-05-21 05:00:00"));
            eventDT.Rows.Add(Convert.ToDateTime("2020-05-21 06:00:00"));

            this.Controls.Add(GetChart(valueDT, eventDT));

        public ChartFX.WinForms.Chart GetChart(DataTable valueDT, DataTable eventDT)
            ChartFX.WinForms.Chart chart = new ChartFX.WinForms.Chart();
            chart.Data.Series = 2;

            chart.Series[0].Text = "value";
            for(int i = 0; i < valueDT.Rows.Count; i++)
                DataRow r = valueDT.Rows;
                chart.Data.X[0, i] = Convert.ToDateTime(r["time"]).ToOADate();
                chart.Data.Y[0, i] = Convert.ToInt32(r["value"]);

            chart.Series[1].Text = "event";
            for(int i = 0; i < eventDT.Rows.Count; i++)
                DataRow r = eventDT.Rows;
                chart.Data.X[1, i] = Convert.ToDateTime(r["time"]).ToOADate();
                chart.Data.Y[1, i] = 10;

            chart.AllSeries.Gallery = ChartFX.WinForms.Gallery.Bar;
            ((ChartFX.WinForms.Galleries.Bar)chart.GalleryAttributes).Overlap = true;
            chart.AllSeries.Gallery = ChartFX.WinForms.Gallery.Lines;

            chart.AxisY.Max = 10;
            chart.AxisY.Min = 0;

            chart.AxisX.LabelsFormat.CustomFormat = "MM-dd HH:mm";
            chart.AxisX.LabelsFormat.Format = ChartFX.WinForms.AxisFormat.DateTime;

            chart.Series[1].Gallery = ChartFX.WinForms.Gallery.Bar;
            chart.Series[1].Volume = 1;

            chart.Dock = DockStyle.Fill;
            return chart;

Edited by isaac
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...