Jump to content
Software FX Community

Recommended Posts

Posted

I'm trying to read an XML file to populate a Gantt chart. I have created a sample chart in a WinForm app, populated it with data from code, and exported the XML schema for the properties as follows:

 

<?xml version="1.0" encoding="UTF-8"?>

<CFX7>

<PANES>

<ITEM index="0">

<AXES>

<ITEM index="0">

<LABELSFORMAT>

<FORMAT>Date</FORMAT>

</LABELSFORMAT>

<POSITION>Far</POSITION>

<TITLE>

<TEXT></TEXT>

</TITLE>

</ITEM>

</AXES>

</ITEM>

</PANES>

<AXESX>

<ITEM index="0">

<GRIDS>

<MAJOR>

<VISIBLE>False</VISIBLE>

</MAJOR>

</GRIDS>

<LABELS>

<ITEM>P2</ITEM>

<ITEM>P1</ITEM>

</LABELS>

<TITLE>

<TEXT></TEXT>

</TITLE>

</ITEM>

</AXESX>

<ALLSERIES>

<GALLERYARRAY type="ChartFX.WinForms.Internal.IGalleryType[]">

<ITEM index="0" type="ChartFX.WinForms.Galleries.Line"/>

<ITEM index="19" type="ChartFX.WinForms.Galleries.Bar"/>

</GALLERYARRAY>

<GALLERY>Gantt</GALLERY>

</ALLSERIES>

<SERIES>

<ITEM index="0"/>

</SERIES>

<LEGENDBOX>

<VISIBLE>False</VISIBLE>

</LEGENDBOX>

<DATAGRID>

<VISIBLE>True</VISIBLE>

</DATAGRID>

<BORDER type="ChartFX.WinForms.Adornments.ImageBorder" assembly="ChartFX.WinForms.Adornments, Version=7.0.4770.21916, Culture=neutral, PublicKeyToken=a1878e2052c08dce"/>

<BACKGROUND type="ChartFX.WinForms.Adornments.GradientBackground" assembly="ChartFX.WinForms.Adornments, Version=7.0.4770.21916, Culture=neutral, PublicKeyToken=a1878e2052c08dce">

<COLORS type="ChartFX.WinForms.Adornments.GradientBackground+ColorCollection" assembly="ChartFX.WinForms.Adornments,  Version=7.0.4770.21916, Culture=neutral, PublicKeyToken=a1878e2052c08dce"/>

</BACKGROUND>

</CFX7>

 

Now I can't figure out what is the XML format for the data. In the docs it's said that we need to provide a pair of values for each data point, which in code is done by assigning values to the YFrom and Y properties, like this:

chart.AxisX.Labels[nPoints] = "P2";

chart.Data.YFrom[nSeries, nPoints] = new DateTime(2013, 8, 30).ToOADate();

chart.Data.Y[nSeries, nPoints] = new DateTime(2013, 9, 30).ToOADate(); 

 

So I tried the following data XML, and many other combinations and formats, but no success:

<CHARTFX>

<COLUMNS>

  <COLUMN NAME="Project" TYPE="String"/>

  <COLUMN NAME="Start" TYPE="Float"/>

  <COLUMN NAME="Finish" TYPE="Float" />

</COLUMNS>

<ROW Project="P2" Start="41518" Finish="41562"/>

<ROW Project="P1" Start="41516" Finish="41547"/>

</CHARTFX>

But the result with this is two bars for each Project, and not a single bar starting and finishing at the desired dates (note that I have transformed the dates to the OADate equivalent, as I was getting errors using the Date or DateTime type for the columns).

Can anyone help me, please! This is really important and urgent!

Thanks in advance! 

Posted

You need to set up your field mapping before passing the data to the chart. This worked for me:

chart1.Import(FileFormat.Xml, "C:\\temp\\chart.cfx");

 

chart1.DataSourceSettings.Fields.Add(
new FieldMap("Project", FieldUsage.Label));

chart1.DataSourceSettings.Fields.Add(

new FieldMap("Start", FieldUsage.FromValue));chart1.DataSourceSettings.Fields.Add(new FieldMap("Finish", FieldUsage.Value));

XmlDataProvider cfxXML = new XmlDataProvider();string dataPath = "C:\\temp\\data.xml";

cfxXML.Load(dataPath);

chart1.DataSourceSettings.DataSource = cfxXML;

Posted

Thanks AndreG!

It really works when I have access to the source code! Well done!

In my case it's a commercial web application that is not mine, but it allows me to provide the XML files to include a chart as a "widget" in a dashboard, thus I can't change their source code.

So far I am able to create any kind of chart, given the two XML files (one for the properties and another for the data), except the Gantt chart. :(

But that's a good direction and I will send this code to the app provider and see if they can do anything about it.

Meanwhile, if anyone have another idea without changing the code, please keep it coming. :)

Cheers!

Posted

Oh, you can set field mapping on the XML too. Try this:

<?xml version="1.0" encoding="UTF-8"?>

<CFX7>

 <PANES>

<ITEM index="0">

 <AXES>

<ITEM index="0">

 <LABELSFORMAT>

<FORMAT>Date</FORMAT>

 </LABELSFORMAT>

 <POSITION>Far</POSITION>

 <TITLE>

<TEXT></TEXT>

 </TITLE>

</ITEM>

 </AXES>

</ITEM>

 </PANES>

 <AXESX>

<ITEM index="0">

 <GRIDS>

<MAJOR>

 <VISIBLE>False</VISIBLE>

</MAJOR>

 </GRIDS>

 <LABELS>

<ITEM>

 P2

</ITEM>

<ITEM>

 P1

</ITEM>

 </LABELS>

 <TITLE>

<TEXT></TEXT>

 </TITLE>

</ITEM>

 </AXESX>

 <ALLSERIES>

<GALLERYARRAY type="ChartFX.WinForms.Internal.IGalleryType[]">

 <ITEM index="0" type="ChartFX.WinForms.Galleries.Line"/>

 <ITEM index="19" type="ChartFX.WinForms.Galleries.Bar"/>

</GALLERYARRAY>

<GALLERY>Gantt</GALLERY>

 </ALLSERIES>

 <SERIES>

<ITEM index="0"/>

 </SERIES>

 <LEGENDBOX>

<VISIBLE>False</VISIBLE>

 </LEGENDBOX>

 <DATAGRID>

<VISIBLE>True</VISIBLE>

 </DATAGRID>

 <BORDER type="ChartFX.WinForms.Adornments.ImageBorder" assembly="ChartFX.WinForms.Adornments, Version=7.0.4770.21916, Culture=neutral, PublicKeyToken=a1878e2052c08dce"/>

 <BACKGROUND type="ChartFX.WinForms.Adornments.GradientBackground" assembly="ChartFX.WinForms.Adornments, Version=7.0.4770.21916, Culture=neutral, PublicKeyToken=a1878e2052c08dce">

<COLORS type="ChartFX.WinForms.Adornments.GradientBackground+ColorCollection" assembly="ChartFX.WinForms.Adornments, Version=7.0.4770.21916, Culture=neutral, PublicKeyToken=a1878e2052c08dce"/>

 </BACKGROUND>

 <DATASOURCESETTINGS>

<FIELDS>

 <ITEM>

<NAME>Project</NAME>

<USAGE>Label</USAGE>

 </ITEM>

 <ITEM>

<NAME>Start</NAME>

<USAGE>FromValue</USAGE>

 </ITEM>

 <ITEM>

<NAME>Finish</NAME>

<USAGE>Value</USAGE>

 </ITEM>

</FIELDS>

 </DATASOURCESETTINGS>

</CFX7>

Posted

Hi AndreG,

Once again, thank you for your prompt and accurate answer! Indeed, after I set the DataSourceSettings in code as you mentioned and export the XML settings it renders exactly as you wrote above. Thus I would expect it to work when importing the correct XML in the web app, but it doesn't... :(

I have attached the screenshot from the web app for your review. 

Here is the VB.NET code that is used by the web page to draw the chart (I found it in a folder in the inetpub structure):

 

        customChart.Import(FileFormat.Xml, chartXMLfile)

        customChart.Border = New SimpleBorder(SimpleBorderType.None)

        SetFontSizes(isZoom)

        'DataBinding

        Dim id As Integer = GetRandomNumber()

        Dim ds As New XmlDataSource()

        ds.DataFile = chartDataXMLfile

        ds.ID = id

        Me.Controls.Add(ds)

        customChart.DataSourceID = ds.ID

 

I can't see anything that could potentially be interfering in the process of importing the settings XML file, neither the data XML file. Can you spot any culprit? :)

I really appreciate your help! Cheers!

Posted

Finally I made it!! I had to insert the bold lines below into the source code for the ascx.vb component called to draw each widget/chart on the web page:

 

        customChart.Import(FileFormat.Xml, chartXMLfile)

        customChart.Border = New SimpleBorder(SimpleBorderType.None)


        If chartXMLfile.Contains("Gantt") Then

            customChart.DataSourceSettings.Fields.Add(New FieldMap("Project", FieldUsage.Label))

            customChart.DataSourceSettings.Fields.Add(New FieldMap("Start", FieldUsage.FromValue))

            customChart.DataSourceSettings.Fields.Add(New FieldMap("Finish", FieldUsage.Value))

        End If


        SetFontSizes(isZoom)

        'DataBinding

        Dim id As Integer = GetRandomNumber()

        Dim ds As New XmlDataSource()

        ds.DataFile = chartDataXMLfile

        ds.ID = id

        Me.Controls.Add(ds)

        customChart.DataSourceID = ds.ID

 

Now I'm naming my XML files containing a Gantt chart with the "Gantt" string in them, so I know which ones need the extra field mapping. Not sure why with this particular application the XML field mapping definition is not working. Fortunately I had this "open door" to allow me to accomplish the mission!

Thanks AndreG for all the hints! They were crucial and really helpful! Cheers! 

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.

×
×
  • Create New...