using System;
using System.Collections.Generic;
using System.Text;
namespace FusionCharts.WebParts
{
class ChartXmlWriter
{
private Plots _plots = null;
private string _chartTitle = "";
private string _xTitle = "";
private string _yTitle = "";
public int YDecimalPrecision = 0;
public bool YNumberScale = false;
public string YNumberPrefix = "";
private string _colors = "";
public ChartXmlWriter(Plots plots, string ChartTitle, string XTitle, string YTitle, string Colors)
{
_plots = plots;
_chartTitle = ChartTitle;
_xTitle = XTitle;
_yTitle = YTitle;
_colors = Colors;
}
///
/// Generate the nice XML output for fusion charts
///
public string WriteXml()
{
// We first convert color (string) into a nice array
string[] separator = { ";" };
string[] colorsArray = _colors.Split(separator, StringSplitOptions.RemoveEmptyEntries);
StringBuilder sb = new StringBuilder();
// We open the graph tag with a few parameters
sb.AppendLine("");
for (int i = 0; i < _plots.Count(); i++)
{
// We try to compute the color
string color = "";
try
{
color = colorsArray[i % (colorsArray.Length)]; // computes to color to use
}
catch { } // if we fail we skip the error, default color will be used
string x = _plots.GetX(i);
// We always have exactly one series
List yvalues = _plots.GetY(i);
double y0 = yvalues[0];
if (!Double.IsNaN(y0))
{
// We add a line to the XML
sb.Append("");
}
}
// We close the graph tag opened previously
sb.AppendLine("");
// We finally return the xml data
return sb.ToString();
}
}
}