Jump to content
Software FX Community

Creating Multiple Charts inside an ASP:DataList control


User (Legacy)

Recommended Posts

Posted

I have a DataList control on a page and I'm trying to create multiple charts 

based on its DataSource. The DataList control is bound to a List<Document>

generic list class. Document has a property called Topics. Topics is a

List<Topic> generic list class again. Topic has a property called Term and

a property called Probability. Since I can't declaratively set the

DataSource property, I'm trying to bind the chart to a datasource on the

ItemDataBound event of the DataList control. I've attached an image showing

what the output looks like. I can tell that it IS in fact binding because

the correct number of spokes appear on the Radar chart, however none of the

values are appearing so it appears that that FieldMapping isn't being

applied? Is there something I'm doing wrong?

Thanks,

Frank

Here is what the code looks like:

protected void DataListRadar_ItemDataBound(object sender,

DataListItemEventArgs e)

{

ChartFX.WebForms.Chart chart = ((ChartFX.WebForms.Chart)e.Item.Controls[3]);

chart.DataSource = ((Document)e.Item.DataItem).Topics;

chart.DataSourceSettings.Fields.Add(new FieldMap("Term", FieldUsage.Label));

chart.DataSourceSettings.Fields.Add(new FieldMap("Probability",

FieldUsage.Value));

chart.DataBind();

}

<asp:DataList ID="DataListRadar" runat="server" RepeatColumns="3"

RepeatDirection="Horizontal" OnDataBinding="DataListRadar_DataBinding"

OnItemDataBound="DataListRadar_ItemDataBound">

<ItemTemplate>

<chartfx7:Chart ID="Chart1" runat="server" Height="200px" Width="200px"

PlotAreaColor="255, 255, 255"

RandomData-Series="1" BackColor="#FFFFFF">

<Series>

<chartfx7:SeriesAttributes Text="Probability" />

</Series>

<DataSourceSettings>

<Fields>

<chartfx7:FieldMap DisplayName="Probability" Name="Probability"

Usage="Value" />

<chartfx7:FieldMap DisplayName="Term" Name="Term" Usage="Label" />

</Fields>

</DataSourceSettings>

<AllSeries Gallery="Radar">

</AllSeries>

<SpecialObjects>

<chartfx.webforms.adornments.simpleborder

assemblyname="ChartFX.WebForms.Adornments"

color="109, 125, 138"

type="None"></chartfx.webforms.adornments.simpleborder>

<chartfx.webforms.adornments.solidbackground

assemblyname="ChartFX.WebForms.Adornments"></chartfx.webforms.adornments.solidbackground>

<chartfx.webforms.galleries.radar fillarea="True"

showlines="False"></chartfx.webforms.galleries.radar>

</SpecialObjects>

<LegendBox Visible="False">

</LegendBox>

<AxisX Max="360" Min="0">

</AxisX>

</chartfx7:Chart>

</ItemTemplate>

</asp:DataList>

Posted

I am unable to reproduce this problem.

I tried with my own Object Data Source and with your code and it works fine,

I get the values from my data. For what I understand, my structure is very

similar to yours.

Make sure you are using the latest Service Pack. If you still can't solve

the problem, please attach a sample project that reproduces it.

Here is the the structure of my object data source:

[DataObject(true)]

public class Person

{

private int m_age;

public int Age {

get { return m_age; }

set { m_age = value; }

}

private int m_zip;

public int Zip {

get { return m_zip; }

set { m_zip = value; }

}

private string m_firstname;

public string FirstName {

get {

return m_firstname;

}

set {

m_firstname = value;

}

}

private string m_lastName;

public string LastName {

get {

return m_lastName;

}

set {

m_lastName = value;

}

}

private Car[] m_cars;

public Car[] Cars {

get {

return m_cars;

}

set { m_cars = value; }

}

[DataObjectMethod(DataObjectMethodType.Select,true)]

public static List<Person> GetPersons ()

{

List<Person> people = new List<Person>();

// Populate

return people;

}

}

[DataObject(true)]

public class Car

{

public Car (string type, double price)

{

Type = type;

Price = price;

}

public string Type {

get {

return m_dfirstname;

}

set {

m_dfirstname = value;

}

}

private string m_dfirstname;

public double Price {

get {

return m_price;

}

set {

m_price = value;

}

}

private double m_price;

}

--

Francisco Padron

www.chartfx.com

Posted

When you say it works fine, how are you doing your databinding? Could you 

post your datalist declaration or how you are doing your bindings?

Thanks.

"SoftwareFX Support" <noreply@softwarefx.com> wrote in message

news:jHKBPuj5GHA.2308@webserver3.softwarefx.com...

>I am unable to reproduce this problem.

>

> I tried with my own Object Data Source and with your code and it works

> fine, I get the values from my data. For what I understand, my structure

> is very similar to yours.

>

> Make sure you are using the latest Service Pack. If you still can't solve

> the problem, please attach a sample project that reproduces it.

>

> Here is the the structure of my object data source:

>

> [DataObject(true)]

>

> public class Person

>

> {

>

> private int m_age;

>

> public int Age {

>

> get { return m_age; }

>

> set { m_age = value; }

>

> }

>

> private int m_zip;

>

> public int Zip {

>

> get { return m_zip; }

>

> set { m_zip = value; }

>

> }

>

> private string m_firstname;

>

> public string FirstName {

>

> get {

>

> return m_firstname;

>

> }

>

> set {

>

> m_firstname = value;

>

> }

>

> }

>

> private string m_lastName;

>

> public string LastName {

>

> get {

>

> return m_lastName;

>

> }

>

> set {

>

> m_lastName = value;

>

> }

>

> }

>

> private Car[] m_cars;

>

> public Car[] Cars {

>

> get {

>

> return m_cars;

>

> }

>

> set { m_cars = value; }

>

> }

>

> [DataObjectMethod(DataObjectMethodType.Select,true)]

>

> public static List<Person> GetPersons ()

>

> {

>

> List<Person> people = new List<Person>();

>

> // Populate

>

> return people;

>

> }

>

> }

>

> [DataObject(true)]

>

> public class Car

>

> {

>

> public Car (string type, double price)

>

> {

>

> Type = type;

>

> Price = price;

>

> }

>

> public string Type {

>

> get {

>

> return m_dfirstname;

>

> }

>

> set {

>

> m_dfirstname = value;

>

> }

>

> }

>

> private string m_dfirstname;

>

> public double Price {

>

> get {

>

> return m_price;

>

> }

>

> set {

>

> m_price = value;

>

> }

>

> }

>

> private double m_price;

>

> }

>

>

> --

> Francisco Padron

> www.chartfx.com

>

>

Posted

I'm doing the same code you have:

protected void DataList1_ItemDataBound (object sender,DataListItemEventArgs

e) {

ChartFX.WebForms.Chart chart = ((ChartFX.WebForms.Chart)e.Item.Controls[1]);

chart.DataSource = ((ObjectData.Person)e.Item.DataItem).Cars;

chart.DataSourceSettings.Fields.Add(new FieldMap("Type", FieldUsage.Label));

chart.DataSourceSettings.Fields.Add(new FieldMap("Price",

FieldUsage.Value));

chart.DataBind();

--

Francisco Padron

www.chartfx.com

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...