Jump to content
Software FX Community

Bar Chart X-Axis Problem


murugananth
 Share

Recommended Posts

Please find the sample code below.

Chart.aspx

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Chart.aspx.cs" Inherits="Chart" %>

<%

@ Register Assembly="ChartFX.WebForms" Namespace="ChartFX.WebForms" TagPrefix="chartfx" %><%@ Register Assembly="ChartFX.WebForms.Adornments" Namespace="ChartFX.WebForms.Adornments" TagPrefix="chartfxadornments" %>

<%

@ Register Assembly="ChartFX.WebForms" Namespace="ChartFX.WebForms.Galleries" TagPrefix="chartfx7galleries" %><html xmlns="http://www.w3.org/1999/xhtml" >

<

head runat="server"><title>Untitled Page</title>

</

head>

<

body>

<form id="form1" runat="server">

<chartfx:Chart ID="ChartReport" EnableViewState="false" AllSeries-Gallery="Bar" Height="99%" Width = "100%" runat="server">

 

</chartfx:Chart>

</form></body>

</

html>

---------------------------------------------------------------------------------------------------------------------------

Chart.aspx.cs

using

System;

using

System.Data;

using

System.Configuration;

using

System.Collections;

using

System.Web;

using

System.Web.Security;

using

System.Web.UI;

using

System.Web.UI.WebControls;

using

System.Web.UI.WebControls.WebParts;

using

System.Web.UI.HtmlControls;

using

ChartFX.WebForms;

using

ChartFX.WebForms.DataProviders;

public

partial class Chart : System.Web.UI.Page

{

protected void Page_Load(object sender, EventArgs e)

{

// code for DataTableDataTable dt = new DataTable();

DataColumn dc1 = new DataColumn();dc1.ColumnName = "X";

dc1.DataType =

Type.GetType("System.Int32");DataColumn dc2 = new DataColumn();

dc2.ColumnName =

"Y";dc2.DataType = Type.GetType("System.Int32");

dt.Columns.Add(dc1);

dt.Columns.Add(dc2);

DataRow dr1,dr2,dr3,dr4,dr5;

dr1 = dt.NewRow();

dr2 = dt.NewRow();

dr3 = dt.NewRow();

dr4 = dt.NewRow();

dr5 = dt.NewRow();

dr1["X"] = 1;

dr1[

"Y"] = 50240;dr2["X"] = 2;

dr2[

"Y"] = 6162;dr3["X"] = 3;

dr3[

"Y"] = 248;dr4["X"] = 4;

dr4[

"Y"] = 500;dr5["X"] = 5;dr5["Y"] = 150;

dt.Rows.Add(dr1);

dt.Rows.Add(dr2);

dt.Rows.Add(dr3);

dt.Rows.Add(dr4);

dt.Rows.Add(dr5);

// Code to generate Bar Chart ChartReport.RenderFormat = ".NET";

ChartReport.Height =

Unit.Percentage(99);ChartReport.Width = Unit.Percentage(100);

ChartReport.Gallery =

Gallery.Bar;ChartReport.View3D.Enabled = true;

ChartReport.View3D.BoxThickness = 10;

ChartReport.AxisX.LabelsFormat.Format = AxisFormat.Number;

ChartReport.AxisX.Title.Text =

"X";ChartReport.AxisY.Title.Text = "Y";

DataTableProvider data = new ChartFX.WebForms.DataProviders.DataTableProvider(dt);CrosstabDataProvider cfxCT = new CrosstabDataProvider();

cfxCT.DataSource = data;

ChartReport.DataSourceSettings.Fields.Add(new FieldMap("X", FieldUsage.RowHeading));

ChartReport.DataSourceSettings.Fields.Add(

new FieldMap("Y", FieldUsage.ColumnHeading));ChartReport.DataSourceSettings.Fields.Add(new FieldMap("Y", FieldUsage.Value));

ChartReport.DataSource = cfxCT;

ChartReport.RecalculateScale();

}

}

Link to comment
Share on other sites

 Not sure why you are using crosstab there. Or why you set 2 different FieldUsages to one field. Take a look at the Resource Center, it explains on which cases to use the crosstab. Try the following.

// Code to generate Bar Chart   Chart1.RenderFormat = ".NET";   Chart1.Height = Unit.Percentage(99);   Chart1.Width = Unit.Percentage(100);   Chart1.Gallery = Gallery.Bar;   Chart1.View3D.Enabled = true;   Chart1.View3D.BoxThickness = 10;   Chart1.AxisX.LabelsFormat.Format = AxisFormat.Number;   Chart1.AxisX.Title.Text = "X";   Chart1.AxisY.Title.Text = "Y";   DataTableProvider data = new ChartFX.WebForms.DataProviders.DataTableProvider(dt);   Chart1.DataSourceSettings.Fields.Add(new FieldMap("X", FieldUsage.Label));   Chart1.DataSourceSettings.Fields.Add(new FieldMap("Y", FieldUsage.Value));   Chart1.DataSource = data;   //Chart1.RecalculateScale(); No need for this

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.

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

 Share

×
×
  • Create New...