Jump to content
Software FX Community

Stacked bar chart with DateTime x axis does not show date time labels, even when labelsformat specified


Recommended Posts

I was having an issue with this in a larger project, so I created a empty one just to isolate the problem.  I have an empty windows form on which I dropped a single chart.  I made no property changes to the chart (via the properties window).  In the form load event, I have the following code:

private void Form1_Load(object sender, EventArgs e)
chart1.Gallery  = Gallery.Bar;
chart1.AllSeries.Stacked = Stacked.Normal;
chart1.AxisX.LabelsFormat.Format = AxisFormat.Time;

DataTable t = new DataTable();

t.Columns.Add("time", typeof(DateTime));
t.Columns.Add("yvalue1", typeof(long));
t.Columns.Add("yvalue2", typeof(long));

DataRow r1 = t.NewRow();
DataRow r2 = t.NewRow();

r1["time"] = DateTime.Now;
r1["yvalue1"] = 10;
r1["yvalue2"] = 25;  
r2["time"] = DateTime.Now.AddMinutes(-100);
r2["yvalue1"] = 50;
r2["yvalue2"] = 75;  


chart1.DataSourceSettings.Fields.Add(new FieldMap("time", FieldUsage.XValue));
chart1.DataSourceSettings.Fields.Add(new FieldMap("yvalue1", FieldUsage.Value));
chart1.DataSourceSettings.Fields.Add(new FieldMap("yvalue2", FieldUsage.Value));

chart1.DataSource = t;


When I run the app, I get the following screen:

Posted Image

 Notice there are NO datetime labels for the bar charts!!!!!


For reference, here is the generated designer code:

private void InitializeComponent()
  this.chart1 = new ChartFX.WinForms.Chart();
  // chart1
  this.chart1.Location = new System.Drawing.Point(12, 12);
  this.chart1.Name = "chart1";
  this.chart1.Size = new System.Drawing.Size(898, 618);
  this.chart1.TabIndex = 0;
  // Form1
  this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
  this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
  this.ClientSize = new System.Drawing.Size(922, 642);
  this.Name = "Form1";
  this.Text = "Form1";
  this.Load += new System.EventHandler(this.Form1_Load);



Any ideas? ???????????  I am literally pulling my hair out over this.  I've tried lots of different things, but to no avail (including just setting things in the properties dialog, etc, and setting various other properties programmatically).

Link to comment
Share on other sites

Hi superqd

You are trying to set the following

chart1.DataSourceSettings.Fields.Add(new FieldMap("time", FieldUsage.XValue));

and this is not compatible with bar gallery, Bar gallery is not an X-Y chart. 

If you want to set date or times in the X-Axis labels (using Bar gallery), you should set the labels manually:

chart1.AxisX.Labels[0] = "Your text";

Carlos Chaves


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...