Exemplo n.º 1
0
 /// <summary>
 /// Constructs the label with the default values
 /// </summary>
 /// <param name="valueType">The value type</param>
 public ChartAxisLabel
 (
     ChartValueType valueType
 )
 {
     this.IsEmpty   = true;
     this.ValueType = valueType;
 }
Exemplo n.º 2
0
 public SeriesSettingOption(ChartValueType XValueType = ChartValueType.Auto, ChartValueType YValueType = ChartValueType.Auto)
 {
     this.XValueType  = XValueType;
     this.YValueType  = YValueType;
     this.AxisTypeOfX = AxisType.Primary;
     this.AxisTypeOfY = AxisType.Primary;
     Color            = Color.Blue;
 }
Exemplo n.º 3
0
 /// <summary>
 /// Object constructor.
 /// </summary>
 /// <param name="value">Value to be formatted.</param>
 /// <param name="format">Format string.</param>
 /// <param name="valueType">Value type..</param>
 /// <param name="localizedValue">Localized value.</param>
 /// <param name="senderTag">Chart element object tag.</param>
 /// <param name="elementType">Chart element type.</param>
 internal FormatNumberEventArgs(double value, string format, ChartValueType valueType, string localizedValue, object senderTag, ChartElementType elementType)
 {
     _value         = value;
     _format        = format;
     _valueType     = valueType;
     LocalizedValue = localizedValue;
     _senderTag     = senderTag;
     _elementType   = elementType;
 }
        public static void ChartSetup(Chart chart, String seriesName, int borderWidth, Color color, SeriesChartType chartType, ChartValueType xValueType) {
            Series newSeries = new Series(seriesName);
            newSeries.ChartType = chartType;
            newSeries.BorderWidth = borderWidth;
            newSeries.Color = color;
            newSeries.XValueType = xValueType;
            chart.Series.Add(newSeries);

        }
Exemplo n.º 5
0
        /// <summary>
        /// Метод задания параметров линии
        /// </summary>
        /// <param name="ChartArea">Название чарта к которому привязана линия</param>
        /// <param name="XValueType">Тип чарта</param>
        /// <param name="Line">тип линии</param>
        /// <param name="BorderWidth">толщина линии</param>
        public Series extSeries(string ChartArea, ChartValueType XValueType, SeriesChartType Line, int BorderWidth)
        {
            Series series = new Series();

            series.ChartArea   = ChartArea;
            series.XValueType  = XValueType;
            series.ChartType   = Line;
            series.BorderWidth = BorderWidth;
            return(series);
        }
Exemplo n.º 6
0
        private void CreateChartStats(BotClass bot, Chart graph, ChartValueType valueType = ChartValueType.Auto)
        {
            if (Program.Mainform != null && graph != null)
            {
                try
                {
                    Program.Mainform.Invoke(new Action(() =>
                    {
                        try
                        {
                            if (bot.IsRunning)
                            {
                                Series serie = graph.Series.FirstOrDefault(x => x.Name == bot.Name);
                                if (serie == null)
                                {
                                    // Add Series
                                    graph.Series.Add(bot.Name);
                                    graph.Series[bot.Name].ChartType = SeriesChartType.FastLine;
                                    graph.Series[bot.Name].Points.Add(0);
                                    graph.Series[bot.Name].YAxisType       = AxisType.Primary;
                                    graph.Series[bot.Name].YValueType      = valueType;
                                    graph.Series[bot.Name].IsXValueIndexed = false;

                                    graph.Series[bot.Name].Color = Color.Black;
                                    foreach (
                                        Color color in
                                        ChartColors.Where(color => graph.Series.All(x => x.Color != color))
                                        )
                                    {
                                        graph.Series[bot.Name].Color = color;
                                    }
                                    graph.Series[bot.Name].Name = bot.Name;
                                }
                            }
                            else
                            {
                                Series serie = graph.Series.FirstOrDefault(x => x.Name == bot.Name);
                                if (serie != null)
                                {
                                    graph.Series.Remove(serie);
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            DebugHelper.Exception(ex);
                        }
                    }));
                }
                catch (Exception ex)
                {
                    DebugHelper.Exception(ex);
                }
            }
        }
Exemplo n.º 7
0
        private Series CreateSeries(string name, SeriesChartType chartType, int borderWidth, Color color, ChartDashStyle borderDashStyle,
            ChartValueType valueType, string legendText)
        {
            Series series = new Series(name);
            series.ChartType = chartType;
            series.BorderWidth = borderWidth;
            series.BorderDashStyle = borderDashStyle;
            series.Color = color;
            series.XValueType = valueType;
            series.IsValueShownAsLabel = true;
            series.LegendText = legendText;

            return series;
        }
Exemplo n.º 8
0
        public static void AddSeries(this Chart chartMain, string ymembers, ChartValueType valueType)
        {
            Series series1 = new Series
            {
                Name          = $"series_{ymembers}",
                ChartArea     = "ChartArea1",
                ChartType     = SeriesChartType.Line,
                Legend        = "Legend1",
                XValueType    = ChartValueType.DateTime,
                XValueMember  = "ts",
                YValueMembers = ymembers,
                YValueType    = valueType,
                Color         = GetRandomColor()
            };

            chartMain.Series.Add(series1);
        }
Exemplo n.º 9
0
        /// <summary>
        /// Converts value to string using specified format.
        /// </summary>
        /// <param name="chart">Reference to the chart object.</param>
        /// <param name="obj">Reference to the object being formatted.</param>
        /// <param name="objTag">Additional object tag.</param>
        /// <param name="value">Value converted to string.</param>
        /// <param name="format">Format string.</param>
        /// <param name="valueType">Value type.</param>
        /// <param name="elementType">Chart element type being formatted.</param>
        public static string FormatValue(
            ChartService chart,
            object obj,
            object objTag,
            double value,
            string format,
            ChartValueType valueType,
            ChartElementType elementType)
        {
            format ??= string.Empty;
            string convertionFormat = format;
            string result           = "";

            // Make sure value index is part of the format
            if (convertionFormat != null && convertionFormat.Length > 0)
            {
                int bracketIndex = convertionFormat.IndexOf('{', 0);
                if (bracketIndex >= 0)
                {
                    while (bracketIndex >= 0)
                    {
                        // If format is not followed by the value index
                        if (!convertionFormat[bracketIndex..].StartsWith("{0:", StringComparison.Ordinal))
Exemplo n.º 10
0
        /// <summary>
        /// 输入序列
        /// </summary>
        /// <param name="table"></param>
        /// <param name="SeriesChartType"></param>
        public void DataBind(DataTable table, SeriesChartType SeriesChartType = SeriesChartType.Line)
        {
            InitializeComponent();

            if (table == null || table.Rows.Count == 0)
            {
                return;
            }
            ChartValueType XValueType   = ChartValueType.Double;
            List <Object>  indexes      = new List <object>();
            var            indexColName = "";
            var            firstVal     = table.Rows[0][0];

            if (firstVal is DateTime)
            {
                indexColName = table.Columns[0].ColumnName;
                foreach (DataRow row in table.Rows)
                {
                    indexes.Add((DateTime)(row[indexColName]));
                }
                XValueType = ChartValueType.DateTime;
            }
            else if (Geo.Utils.DateTimeUtil.TryParse(firstVal.ToString()) != DateTime.MinValue)
            {
                indexColName = table.Columns[0].ColumnName;
                foreach (DataRow item in table.Rows)
                {
                    indexes.Add(Geo.Utils.DateTimeUtil.TryParse(item[indexColName]));
                }
                XValueType = ChartValueType.DateTime;
            }
            else
            {
                indexColName = "编号ID";
                int i = 1;
                foreach (var item in table.Rows)
                {
                    indexes.Add(i++);
                }
            }

            // var prevObj = indexes[0];
            //   bool isIndexTime = (prevObj.GetType() == typeof(DateTime));
            Dictionary <string, Series> dic = new Dictionary <string, Series>();

            //var indexColName = table.GetIndexColName();
            foreach (DataColumn name in table.Columns)
            {
                if (name.ColumnName == indexColName)
                {
                    continue;
                }
                Series seriesX = new Series(name.ColumnName);
                seriesX.ChartType    = SeriesChartType;// SeriesChartType.Point;
                seriesX.YValueType   = ChartValueType.Double;
                seriesX.XValueType   = XValueType;
                seriesX.MarkerSize   = 5;
                seriesX.BorderWidth  = 5;
                seriesX.ToolTip      = "#SERIESNAME: #VALX, #VALY";//#LEGENDTEXT // https://msdn.microsoft.com/en-us/library/dd207017.aspx
                dic[name.ColumnName] = seriesX;
            }

            int paramIndex = 0;

            foreach (var item in dic)
            {
                var series = item.Value;
            }
            //  var indexColValues = table.GetIndexValues();
            foreach (var result in dic)//避免集合修改无法遍历
            {
                if (result.Key == indexColName)
                {
                    continue;
                }

                var seriesX    = dic[result.Key];
                int graphIndex = 0;
                int dataIndex  = -1;
                foreach (DataRow row in table.Rows)
                {
                    dataIndex++;
                    var obj = row[result.Key];
                    var val = Geo.Utils.DoubleUtil.TryParse(obj, double.NaN);

                    if (val is Double && Geo.Utils.DoubleUtil.IsValid((Double)val))
                    {
                        seriesX.Points.AddXY(indexes[graphIndex], val);
                    }
                    graphIndex++;
                }
                paramIndex++;
            }

            Init(dic.Values);
        }
Exemplo n.º 11
0
        private void CreateChartStats(BotClass bot, Chart graph, ChartValueType valueType = ChartValueType.Auto)
        {
            if (Program.Mainform != null && graph != null)
            {
                try
                {
                    Program.Mainform.Invoke(new Action(() =>
                    {
                        try
                        {
                            if (bot.IsRunning)
                            {
                                Series serie = graph.Series.FirstOrDefault(x => x.Name == bot.Name);
                                if (serie == null)
                                {
                                    // Add Series
                                    graph.Series.Add(bot.Name);
                                    graph.Series[bot.Name].ChartType = SeriesChartType.FastLine;
                                    graph.Series[bot.Name].Points.Add(0);
                                    graph.Series[bot.Name].YAxisType = AxisType.Primary;
                                    graph.Series[bot.Name].YValueType = valueType;
                                    graph.Series[bot.Name].IsXValueIndexed = false;

                                    graph.Series[bot.Name].Color = Color.Black;
                                    foreach (
                                        Color color in
                                            ChartColors.Where(color => graph.Series.All(x => x.Color != color))
                                        )
                                        graph.Series[bot.Name].Color = color;
                                    graph.Series[bot.Name].Name = bot.Name;
                                }
                            }
                            else
                            {
                                Series serie = graph.Series.FirstOrDefault(x => x.Name == bot.Name);
                                if (serie != null)
                                    graph.Series.Remove(serie);
                            }
                        }
                        catch (Exception ex)
                        {
                            DebugHelper.Exception(ex);
                        }
                    }));
                }
                catch (Exception ex)
                {
                    DebugHelper.Exception(ex);
                }
            }
        }
Exemplo n.º 12
0
 /// <summary>
 /// Метод задания параметров линии
 /// </summary>
 /// <param name="ChartArea">Название чарта к которому привязана линия</param>
 /// <param name="XValueType">????</param>
 /// <param name="Line">тип линии</param>
 /// <param name="BorderWidth">толщина линии</param>
 public Series extSeries(string ChartArea, ChartValueType XValueType, SeriesChartType Line, int BorderWidth)
 {
     Series series = new Series();
     series.ChartArea = ChartArea;
     series.XValueType = XValueType;
     series.ChartType = Line;
     series.BorderWidth = BorderWidth;
     return series;
 }
        public static void ChartSetup(Chart chart, String seriesName, int borderWidth, Color color, SeriesChartType chartType, ChartValueType xValueType)
        {
            Series newSeries = new Series(seriesName);

            newSeries.ChartType   = chartType;
            newSeries.BorderWidth = borderWidth;
            newSeries.Color       = color;
            newSeries.XValueType  = xValueType;
            chart.Series.Add(newSeries);
        }
Exemplo n.º 14
0
        /// <summary>
        /// Converts value to string using specified format.
        /// </summary>
        /// <param name="chart">Reference to the chart object.</param>
        /// <param name="obj">Reference to the object being formatted.</param>
        /// <param name="objTag">Additional object tag.</param>
        /// <param name="value">Value converted to string.</param>
        /// <param name="format">Format string.</param>
        /// <param name="valueType">Value type.</param>
        /// <param name="elementType">Chart element type being formatted.</param>
        public static string FormatValue(
            Chart chart,
            object obj,
            object objTag,
            double value,
            string format,
            ChartValueType valueType,
            ChartElementType elementType)
        {
            format = format ?? String.Empty;
            string convertionFormat = format;
            string result           = "";

            // Make sure value index is part of the format
            if (convertionFormat != null && convertionFormat.Length > 0)
            {
                int bracketIndex = convertionFormat.IndexOf('{', 0);
                if (bracketIndex >= 0)
                {
                    while (bracketIndex >= 0)
                    {
                        // If format is not followed by the value index
                        if (!convertionFormat.Substring(bracketIndex).StartsWith("{0:", StringComparison.Ordinal))
                        {
                            // Check charcter prior to the bracket
                            if (bracketIndex >= 1 && convertionFormat.Substring(bracketIndex - 1, 1) == "{")
                            {
                                continue;
                            }
                            else
                            {
                                // Insert value index in format
                                convertionFormat = convertionFormat.Insert(bracketIndex + 1, "0:");
                            }
                        }

                        bracketIndex = convertionFormat.IndexOf('{', bracketIndex + 1);
                    }
                }
                else
                {
                    convertionFormat = "{0:" + convertionFormat + "}";
                }
            }

            // Date/time formating
            if (valueType == ChartValueType.DateTime ||
                valueType == ChartValueType.DateTimeOffset ||
                valueType == ChartValueType.Date)
            {
                // Set default format
                if (convertionFormat.Length == 0)
                {
                    convertionFormat = "{0:d}";
                    if (valueType == ChartValueType.DateTimeOffset)
                    {
                        convertionFormat += " +0";
                    }
                }

                // Convert date to string
                result = String.Format(CultureInfo.CurrentCulture, convertionFormat, DateTime.FromOADate(value));
            }
            else if (valueType == ChartValueType.Time)
            {
                // Set default format
                if (convertionFormat.Length == 0)
                {
                    convertionFormat = "{0:t}";
                }

                // Convert date to string
                result = String.Format(CultureInfo.CurrentCulture, convertionFormat, DateTime.FromOADate(value));
            }
            else
            {
                bool failedFlag = false;

                // Set default format
                if (convertionFormat.Length == 0)
                {
                    convertionFormat = "{0:G}";
                }

                try
                {
                    // Numeric value formatting
                    result = String.Format(CultureInfo.CurrentCulture, convertionFormat, value);
                }
                catch (FormatException)
                {
                    failedFlag = true;
                }

                // If numeric formatting failed try to format using decimal number
                if (failedFlag)
                {
                    failedFlag = false;
                    try
                    {
                        // Decimal value formatting
                        result = String.Format(CultureInfo.CurrentCulture, convertionFormat, (long)value);
                    }
                    catch (ArgumentNullException)
                    {
                        failedFlag = true;
                    }
                    catch (FormatException)
                    {
                        failedFlag = true;
                    }
                }

                // Return format string as result (literal) if all formatting methods failed
                if (failedFlag)
                {
                    result = format;
                }
            }

            // For the Reporting Services chart a special number formatting
            // handler may be set and used for all formatting needs.
            if (chart != null)
            {
                // Call number formatter
                FormatNumberEventArgs eventArguments = new FormatNumberEventArgs(value, format, valueType, result, objTag, elementType);
                chart.CallOnFormatNumber(obj, eventArguments);
                result = eventArguments.LocalizedValue;
            }

            return(result);
        }
Exemplo n.º 15
0
 public Series CreateChartSeries(Color color, SeriesChartType seriesChartType, ChartValueType xValueType,
                                 AxisType yAxisType, string name)
 {
     return(new Series
     {
         ChartType = seriesChartType,
         XValueType = xValueType,
         YAxisType = yAxisType,
         Color = color,
         IsVisibleInLegend = true,
         Name = name
     });
 }