views:

33

answers:

1

Ok, so in order to provide Data to Fusion Charts I need to give it some XML.. I have narrowed it down to this

myChart.setDataXML("<%Html.RenderPartial("Graph", Model.graph_data); %>");

which renders

myChart.setDataXML("
    <chart caption='Grafico' xAxisName='Factores' yAxisName='Porcentaje' decimals='0' formatNumberScale='0' numberSuffix='%25' yAxisMinValue='0' yAxisMaxValue='100' bgColor='FFFFFF' showBorder='1' bgSWF='/Content/images/LogoGraficas.png' slantLabels='1' labelDisplay='Rotate' baseFontColor='333333'>

<set value='100' label='Pierna' />
        <styles>
            <definition>
                <style name='myShadow' type='Shadow' color='999999' angle='45'/>
            </definition>
            <application>
                <apply toObject='DataValues' styles='myShadow' />
            </application>
        </styles>
    </chart>");

But what I need rendered is..

myChart.setDataXML("<chart caption='Grafico' xAxisName='Factores' yAxisName='Porcentaje' decimals='0' formatNumberScale='0' numberSuffix='%25' yAxisMinValue='0' yAxisMaxValue='100' bgColor='FFFFFF' showBorder='1' bgSWF='/Content/images/LogoGraficas.png' slantLabels='1' labelDisplay='Rotate' baseFontColor='333333'><set value='100' label='Pierna' /><styles><definition><style name='myShadow' type='Shadow' color='999999' angle='45'/></definition><application><apply toObject='DataValues' styles='myShadow' /></application></styles></chart>");

How can I make the RenderPartial give me back the string without the spaces?

A: 

You can try to convert the PartialView output to a string and then manipulate it as u wish.

So what you will end up doing is something like this.

string data = RenderPartialToString("~/..../..../..../Graph.ascx", Model.graph_data);
data.Replace(System.Environment.NewLine, "");
myChart.setDataXML(data);

I know it's not the best solution but it might fix your problem.

Update :

Better Ways to generate your XML is to use : XmlWriter or XmlSerializer or XDocument

I'm not an XML Expert so i don't know which is best for your case but i like the way the XmlSerializer works.

See some examples Here

Manaf Abu.Rous