Esempio n. 1
0
        public chartDataColumn(DataColumn source)
        {
            columnLabel    = source.GetHeading();
            dataFormatting = source.GetFormat();

            if (!source.GetValueType().isNumber())
            {
                escapeValueFormat = "'{0}'";
            }

            foreach (DataRow dr in source.Table.Rows)
            {
                String v = dr[source].toStringSafe("", dataFormatting);
                if (escapeValueFormat != "{0}")
                {
                    v = String.Format(escapeValueFormat, v);
                }
                columnValues.Add(v);
            }
        }
        public String DataToJ3CodeData(DataTable table, params String[] columnToSeries)
        {
            StringBuilder sb = new StringBuilder();

            sb.Append(leftSquareBracket + " ");

            for (int i2 = 0; i2 < columnToSeries.Length; i2++)
            {
                String     column_name = columnToSeries[i2];
                DataColumn dc          = table.Columns[column_name];
                String     label       = dc.GetHeading();

                sb.Append(leftSquareBracket + " " + singleQuoteBracket + label + singleQuoteBracket + " " + dataEntrySeparator + " ");

                for (int i = 0; i < table.Rows.Count; i++)
                {
                    DataRow dr = table.Rows[i];

                    if (i == table.Rows.Count - 1)
                    {
                        sb.Append(dr[dc] + " ");
                    }
                    else
                    {
                        sb.Append(dr[dc] + dataEntrySeparator + " ");
                    }
                }

                if (column_name == columnToSeries.Last())
                {
                    sb.Append(" " + rightSquareBracket);
                }
                else
                {
                    sb.Append(" " + rightSquareBracket + " " + dataEntrySeparator);
                }
            }
            sb.Append(" " + rightSquareBracket);
            return(sb.ToString());
        }
        public chartModel BuildBarChart(DataTable dataTable, String ColumnForXLabel = "")
        {
            var        output     = new chartModel();
            DataColumn dateColumn = null;

            if (ColumnForXLabel != "")
            {
                dateColumn = dataTable.Columns[ColumnForXLabel];
            }


            foreach (DataColumn dc in dataTable.Columns)
            {
                chartDataColumn cdc = new chartDataColumn(dc);
                if (dc == dateColumn)
                {
                    cdc.columnLabel = "x";
                    output.data.dataAxisPairs.Add(new dataAxisXYPair()
                    {
                        XColumnName = "x",
                        YColumnName = "x"
                    });
                    output.axis.Add(new chartAxis()
                    {
                        axisLetter = "x",
                        label      = dateColumn.GetHeading(),
                        axisType   = chartTypeEnum.timeseries,
                        tick       = new chartAxisTick()
                        {
                            format = "%Y-%m-%d"
                        }
                    });
                }
                else
                {
                }

                output.axis.Add(new chartAxis()
                {
                    axisLetter = "y",
                    label      = "y",
                    axisType   = chartTypeEnum.timeseries,
                    tick       = new chartAxisTick()
                    {
                        isFormatJS = true,
                        format     = " d3.format(\",\") "
                    }
                });

                output.data.columns.Add(cdc);
            }

            output.data.type = chartTypeEnum.bar;

            output.chartFormat = new chartTypeFormatting()
            {
                axisType = chartTypeEnum.bar,
                width    = 0.8,
                title    = dataTable.GetTitle()
            };

            return(output);
        }