using System.Collections.Generic;
using System.Text;
namespace Stat.Report
{
    /// <summary>
    /// 柱形报表
    /// </summary>
    public class Rp_3_Column2D
    {
        /// <summary>
        /// 小时流量趋势
        /// </summary>
        /// <param name="list">数据源</param>
        /// <param name="caption">标题</param>
        /// <param name="xAxisName">X轴名称</param>
        /// <param name="yAxisName">Y轴名称</param>
        /// <param name="cPage"></param>
        /// <param name="numberSuffix"></param>
        /// <param name="pSize"></param>
        /// <param name="showValues"></param>
        /// <returns></returns>
        public static string GetXML_Domain(List<Model.StatItem> list, int cPage, int pSize, string caption, string xAxisName, string yAxisName, string numberSuffix, int showValues)
        {

            StringBuilder strXML = new System.Text.StringBuilder();
            strXML.Append("<chart caption='" + caption + "' xAxisName='" + xAxisName + "' yAxisName='" + yAxisName + "' numberSuffix='" + numberSuffix + "' showValues='" + showValues + "'");
            strXML.Append(" palette='2' decimals='2' formatNumberScale='0' useRoundEdges='1'");

            strXML.Append(" alternateHGridColor='FCB541' alternateHGridAlpha='15' divLineColor='FCB541' divLineAlpha='40'");
            strXML.Append(" labelStep='1'");
            strXML.Append(" canvasBorderColor='F7BD62' baseFontColor='000000' lineColor='FCB541' bgColor='FFFFFF' showBorder='0'>");

            if (list != null && list.Count > 0)
            {
                /*--------------------------------------------------------*/
                int st = (cPage - 1) * pSize;
                st = st > list.Count ? list.Count : st;
                int et = st + pSize;
                et = et > list.Count ? list.Count : et;
                /*--------------------------------------------------------*/

                string[] c = Plugin.Common.RpColor();
                int cj = 0;
                for (int i = st; i < et; i++)
                {
                    if (i > 0)
                    {
                        strXML.Append("  <set label='" + FormatDomain(list[i].Name) + "' value='" + list[i].PvCount + "' color='" + c[cj].ToString() + "' toolText='" + FormatDomain(list[i].Name) + "：" + list[i].PvCount + " " + numberSuffix + "' />");

                        cj++;
                        cj = cj >= (c.GetLength(0) - 1) ? 0 : cj; //颜色编号
                    }
                }
            }
            strXML.Append("</chart>");

            return strXML.ToString();

        }
        private static string FormatDomain(string s)
        {
            if (s == "")
            {

                return "输入域名";
            }
            return s;
        }
    }
}
