PDA

View Full Version : [CLOSED] charts from code behind not showing



tMp
Jan 15, 2014, 3:26 PM
I trying to get to know the new charts a little bit better but already when creating a simple sample chart it doesn't show. What did I do wrong?


<%@ Page Language="C#" %>

<%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>

<!DOCTYPE html>

<script runat="server">

protected void Page_Load(object sender, EventArgs e)
{
// create sample data
System.Data.DataTable dt = new System.Data.DataTable();
Random ran = new Random();

System.Data.DataColumn dc = new System.Data.DataColumn("Name");
dc.DataType = System.Type.GetType("System.String");
dt.Columns.Add(dc);
dc = new System.Data.DataColumn("Data");
dc.DataType = System.Type.GetType("System.Int32");
dt.Columns.Add(dc);
System.Data.DataRow dr = dt.NewRow();
dr[0] = "Jan";
dr[1] = ran.Next(0, 100);
dt.Rows.Add(dr); dr = dt.NewRow();
dr[0] = "Feb";
dr[1] = ran.Next(0, 100);
dt.Rows.Add(dr); dr = dt.NewRow();
dr[0] = "Mar";
dr[1] = ran.Next(0, 100);
dt.Rows.Add(dr);


if (!X.IsAjaxRequest)
{
Ext.Net.Panel pnl = new Ext.Net.Panel
{
Title = "Chart Test",
Layout = "FitLayout",
Items =
{
new Chart {
ID = "ChartTest",
Shadow = true,
Animate = true,
Store = {
new Store {
DataSource = dt,
AutoDataBind = true,
Model = {
new Model {
Fields = {
new ModelField { Name = "Name" },
new ModelField { Name = "Data" }
}
}
}
}
},
Axes = {
new NumericAxis { Fields = new string[] { "Data" }, Title = "Number", Minimum = 0 },
new CategoryAxis { Position = Position.Bottom, Fields = new string[] { "Name" }, Title = "Name" }
},
Series = {
new ColumnSeries { Axis = Position.Left, XField = new string[] { "Name" }, YField = new string[] { "Data" } }
}
}
}
};

this.Form.Controls.Add(pnl);
}
}

</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<ext:ResourceManager ID="ResourceManager1" runat="server" />
<div>

</div>
</form>
</body>
</html>


Thanks for a nudge in the right direction.

best regards.

Daniil
Jan 16, 2014, 3:11 AM
Hi @tMp,

Just set up some size for the Panel:)

Width = 400,
Height = 400,

tMp
Jan 16, 2014, 7:37 AM
Ou, shoot. I automatically assumed that it just take the whole space without hight and width.

thank you!

And I found one more ways that the chart is not correctly showing for me:

Uncomment the LegendConfig and you get this: http://forums.ext.net/showthread.php?25723-CLOSED-Create-a-Chart-in-Code-Behind
Do I really have to break the construction apart, or is there another way to do it?


New example.

<%@ Page Language="C#" %>

<%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>

<!DOCTYPE html>

<script runat="server">

protected void Page_Load(object sender, EventArgs e)
{
// create sample data
System.Data.DataTable dt = new System.Data.DataTable();
Random ran = new Random();

System.Data.DataColumn dc = new System.Data.DataColumn("Name");
dc.DataType = System.Type.GetType("System.String");
dt.Columns.Add(dc);
dc = new System.Data.DataColumn("Data");
dc.DataType = System.Type.GetType("System.Int32");
dt.Columns.Add(dc);
System.Data.DataRow dr = dt.NewRow();
dr[0] = "January";
dr[1] = ran.Next(0, 100);
dt.Rows.Add(dr); dr = dt.NewRow();
dr[0] = "February";
dr[1] = ran.Next(0, 100);
dt.Rows.Add(dr); dr = dt.NewRow();
dr[0] = "March is just way too long for this";
dr[1] = ran.Next(0, 100);
dt.Rows.Add(dr);


if (!X.IsAjaxRequest)
{
Ext.Net.Panel pnl = new Ext.Net.Panel
{
Title = "Chart Test",
Layout = "FitLayout",
Width = 300,
Height = 500,
Items =
{
new Chart {
ID = "ChartTest",
Shadow = true,
Animate = true,
//LegendConfig = { Position = LegendPosition.Top },
Store = {
new Store {
DataSource = dt,
AutoDataBind = true,
Model = {
new Model {
Fields = {
new ModelField { Name = "Name" },
new ModelField { Name = "Data" }
}
}
}
}
},
Axes = {
new NumericAxis { Fields = new string[] { "Data" }, Title = "Number", Minimum = 0 },
new CategoryAxis { Position = Position.Bottom, Fields = new string[] { "Name" }, Title = "Name" }
},
Series = {
new ColumnSeries { Axis = Position.Left, XField = new string[] { "Name" }, YField = new string[] { "Data" } }
}
}
}
};

this.Form.Controls.Add(pnl);
}
}

</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<ext:ResourceManager ID="ResourceManager1" runat="server" />
<div>

</div>
</form>
</body>
</html>

Daniil
Jan 16, 2014, 12:07 PM
1) Uncomment the LegendConfig and you get this: http://forums.ext.net/showthread.php?25723-CLOSED-Create-a-Chart-in-Code-Behind
Do I really have to break the construction apart, or is there another way to do it?


Please replace

LegendConfig = { Position = LegendPosition.Top },
with

LegendConfig = new ChartLegend() { Position = LegendPosition.Top },



2) When the Text of the bottom axis is getting to long I either don't see everything or I don't see the text at all. Is there a way how I can confine this text in a box so that it just breaks when it gets too long?

PS: And is there a way that I can force the order of the bars/columns? Like when I have a top (10) select result, it shows me the bars from bottom to top which I would like to change from top to bottom (First record at the top).


Please start new threads for each issue.

Geenin
Jan 16, 2014, 1:48 PM
Hi @tMp,

Just set up some size for the Panel:)

Width = 400,
Height = 400,

Hi Daniil,

It works with Page_Load, but it doesn't work with buttion.OnDirectClick(method), any suggestion?


Paggy

tMp
Jan 16, 2014, 1:52 PM
Thank you, working perfectly.

I am changing my post above, so this thread stays clean.

Geenin
Jan 16, 2014, 2:12 PM
Thank you, working perfectly.

I am changing my post above, so this thread stays clean.


Hi Daniil,

Should I create another thread for my question?

I copied above code and put it in Page_Load, it works perfectly, and then I create a function (LoadChart) and put the code there, also add a Button in the aspx file, and use OnDirectClick="LoadChart", but the chart didn't show up.


Paggy

Daniil
Jan 17, 2014, 4:15 AM
Hi @Paggy,

Yes, please start a new forum thread. If you feel the threads are related, please feel free to cross reference between the two.