当前位置: 首页>>代码示例>>C#>>正文


C# Series.SetCustomProperty方法代码示例

本文整理汇总了C#中System.Windows.Forms.DataVisualization.Charting.Series.SetCustomProperty方法的典型用法代码示例。如果您正苦于以下问题:C# Series.SetCustomProperty方法的具体用法?C# Series.SetCustomProperty怎么用?C# Series.SetCustomProperty使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Windows.Forms.DataVisualization.Charting.Series的用法示例。


在下文中一共展示了Series.SetCustomProperty方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CalculateHistogram

    protected virtual void CalculateHistogram(Series series, DataRow row) {
      series.Points.Clear();
      if (!row.Values.Any()) return;
      int bins = row.VisualProperties.Bins;

      double minValue = row.Values.Min();
      double maxValue = row.Values.Max();
      double intervalWidth = (maxValue - minValue) / bins;
      if (intervalWidth < 0) return;
      if (intervalWidth == 0) {
        series.Points.AddXY(minValue, row.Values.Count);
        return;
      }

      if (!row.VisualProperties.ExactBins) {
        intervalWidth = HumanRoundRange(intervalWidth);
        minValue = Math.Floor(minValue / intervalWidth) * intervalWidth;
        maxValue = Math.Ceiling(maxValue / intervalWidth) * intervalWidth;
      }

      double intervalCenter = intervalWidth / 2;

      double min = 0.0, max = 0.0;
      if (!Double.IsNaN(Content.VisualProperties.XAxisMinimumFixedValue) && !Content.VisualProperties.XAxisMinimumAuto)
        min = Content.VisualProperties.XAxisMinimumFixedValue;
      else min = minValue;
      if (!Double.IsNaN(Content.VisualProperties.XAxisMaximumFixedValue) && !Content.VisualProperties.XAxisMaximumAuto)
        max = Content.VisualProperties.XAxisMaximumFixedValue;
      else max = maxValue + intervalWidth;

      double axisInterval = intervalWidth / row.VisualProperties.ScaleFactor;

      var area = chart.ChartAreas[0];
      area.AxisX.Interval = axisInterval;

      series.SetCustomProperty("PointWidth", "1"); // 0.8 is the default value

      // get the range or intervals which define the grouping of the frequency values
      var doubleRange = DoubleRange(min, max, intervalWidth).Skip(1).ToList();

      // aggregate the row values by unique key and frequency value
      var valueFrequencies = (from v in row.Values
                              where !IsInvalidValue(v)
                              orderby v
                              group v by v into g
                              select new Tuple<double, double>(g.First(), g.Count())).ToList();

      // shift the chart to the left so the bars are placed on the intervals
      if (valueFrequencies.First().Item1 < doubleRange.First())
        series.Points.Add(new DataPoint(min - intervalWidth, 0));

      // add data points
      int j = 0;
      foreach (var d in doubleRange) {
        double sum = 0.0;
        // sum the frequency values that fall within the same interval
        while (j < valueFrequencies.Count && valueFrequencies[j].Item1 < d) {
          sum += valueFrequencies[j].Item2;
          ++j;
        }
        string xAxisTitle = string.IsNullOrEmpty(Content.VisualProperties.XAxisTitle)
                              ? "X"
                              : Content.VisualProperties.XAxisTitle;
        string yAxisTitle = string.IsNullOrEmpty(Content.VisualProperties.YAxisTitle)
                              ? "Y"
                              : Content.VisualProperties.YAxisTitle;
        series.Points.Add(new DataPoint(d - intervalCenter, sum) {
          ToolTip =
            xAxisTitle + ": [" + (d - intervalWidth) + "-" + d + ")" + Environment.NewLine +
            yAxisTitle + ": " + sum
        });
      }
    }
开发者ID:thunder176,项目名称:HeuristicLab,代码行数:73,代码来源:DataTableView.cs

示例2: ConfigureSeries

    private void ConfigureSeries(Series series, DataRow row) {
      RemoveCustomPropertyIfExists(series, "PointWidth");
      series.BorderWidth = 1;
      series.BorderDashStyle = ChartDashStyle.Solid;
      series.BorderColor = Color.Empty;

      if (row.VisualProperties.Color != Color.Empty)
        series.Color = row.VisualProperties.Color;
      else series.Color = Color.Empty;
      series.IsVisibleInLegend = row.VisualProperties.IsVisibleInLegend;

      switch (row.VisualProperties.ChartType) {
        case DataRowVisualProperties.DataRowChartType.Line:
          series.ChartType = SeriesChartType.FastLine;
          series.BorderWidth = row.VisualProperties.LineWidth;
          series.BorderDashStyle = ConvertLineStyle(row.VisualProperties.LineStyle);
          break;
        case DataRowVisualProperties.DataRowChartType.Bars:
          // Bar is incompatible with anything but Bar and StackedBar*
          if (!chart.Series.Any(x => x.ChartType != SeriesChartType.Bar && x.ChartType != SeriesChartType.StackedBar && x.ChartType != SeriesChartType.StackedBar100))
            series.ChartType = SeriesChartType.Bar;
          else {
            series.ChartType = SeriesChartType.FastPoint; //default
            row.VisualProperties.ChartType = DataRowVisualProperties.DataRowChartType.Points;
          }
          break;
        case DataRowVisualProperties.DataRowChartType.Columns:
          series.ChartType = SeriesChartType.Column;
          break;
        case DataRowVisualProperties.DataRowChartType.Points:
          series.ChartType = SeriesChartType.FastPoint;
          break;
        case DataRowVisualProperties.DataRowChartType.Histogram:
          series.ChartType = SeriesChartType.Column;
          series.SetCustomProperty("PointWidth", "1");
          if (!series.Color.IsEmpty && series.Color.GetBrightness() < 0.25)
            series.BorderColor = Color.White;
          else series.BorderColor = Color.Black;
          break;
        case DataRowVisualProperties.DataRowChartType.StepLine:
          series.ChartType = SeriesChartType.StepLine;
          series.BorderWidth = row.VisualProperties.LineWidth;
          series.BorderDashStyle = ConvertLineStyle(row.VisualProperties.LineStyle);
          break;
        default:
          series.ChartType = SeriesChartType.FastPoint;
          break;
      }
      series.YAxisType = row.VisualProperties.SecondYAxis ? AxisType.Secondary : AxisType.Primary;
      series.XAxisType = row.VisualProperties.SecondXAxis ? AxisType.Secondary : AxisType.Primary;
      if (row.VisualProperties.DisplayName.Trim() != String.Empty) series.LegendText = row.VisualProperties.DisplayName;
      else series.LegendText = row.Name;

      string xAxisTitle = string.IsNullOrEmpty(Content.VisualProperties.XAxisTitle)
                      ? "X"
                      : Content.VisualProperties.XAxisTitle;
      string yAxisTitle = string.IsNullOrEmpty(Content.VisualProperties.YAxisTitle)
                            ? "Y"
                            : Content.VisualProperties.YAxisTitle;
      series.ToolTip =
        series.LegendText + Environment.NewLine +
        xAxisTitle + " = " + "#INDEX," + Environment.NewLine +
        yAxisTitle + " = " + "#VAL";
    }
开发者ID:thunder176,项目名称:HeuristicLab,代码行数:64,代码来源:DataTableView.cs


注:本文中的System.Windows.Forms.DataVisualization.Charting.Series.SetCustomProperty方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。