コード例 #1
0
    public static string ConvertChartToSpreadsheetText(ChartControl xyLineChart, char token) {
      int maxPrimitiveLength = 0;
      foreach(ChartPrimitive primitive in xyLineChart.Primitives) {
        maxPrimitiveLength = Math.Max(maxPrimitiveLength, primitive.Points.Count);
      }
      string[] grid = new string[maxPrimitiveLength + 1];
      foreach(ChartPrimitive primitive in xyLineChart.Primitives) {
        int row = 0;
        grid[row] += primitive.Label + " X" + token + primitive.Label + " Y" + token;
        foreach(System.Windows.Point point in primitive.Points) {
          ++row;
          grid[row] += point.X.ToString() + token + point.Y.ToString() + token;
        }
        ++row;
        while(row < grid.Length) {
          grid[row] += token.ToString() + token.ToString();
          ++row;
        }
      }

      StringBuilder sb = new StringBuilder();
      sb.AppendLine(xyLineChart.Title);
      foreach(string line in grid) {
        if(!string.IsNullOrEmpty(line))
          sb.AppendLine(line.Substring(0, line.Length - 1));
      }

      return sb.ToString();
    }
コード例 #2
0
    // ********************************************************************
    // Public Methods
    // ********************************************************************
    #region Public Methods

    public static void CopyChartToClipboard(FrameworkElement plotToCopy, ChartControl chartControl, double width, double height) {
      plotToCopy = plotToCopy ?? chartControl;

      System.Drawing.Bitmap bitmap = CopyFrameworkElementToBitmap(plotToCopy, width, height);
      DataObject dataObject = new DataObject();
      dataObject.SetData(DataFormats.Bitmap, bitmap);
      if(chartControl != null) {
        string text = ChartUtilities.ConvertChartToSpreadsheetText(chartControl, '\t');
        MemoryStream csv = new MemoryStream(Encoding.UTF8.GetBytes(ChartUtilities.ConvertChartToSpreadsheetText(chartControl, ',')));
        dataObject.SetData(DataFormats.Text, text);
        dataObject.SetData(DataFormats.CommaSeparatedValue, csv);
      }
      Clipboard.SetDataObject(dataObject);
    }
コード例 #3
0
    /// <summary>
    /// Gets ChartLines and ChartPolygons for the population line, and
    /// the target line using a baseline.
    /// </summary>
    public static LineAndPolygon ConvertResultsToTargetLineAndPolygon(ChartControl factory, ChartPrimitive populationLine, float[] results, Color color, string label, ChartPrimitiveXY baseLine) {

      // Calculate Target Primitives
      ChartPrimitiveXY targetLine = factory.CreateXY();
      targetLine.LineColor = color;
      targetLine.IsDashed = true;
      targetLine.Label = label + " Target";
      targetLine.IsHitTest = true;

      if(populationLine.Points.Count == results.Length) {
        if(baseLine == null) {
          for(int monthNo = 0; monthNo < results.Length; monthNo += 2) {
            targetLine.AddPoint(new Point((float)monthNo * .5f, results[monthNo]));
            targetLine.AddPoint(new Point((float)monthNo * .5f + 1f, results[monthNo + 1]));
          }
        } else {
          for(int monthNo = 0; monthNo < results.Length; monthNo += 2) {
            targetLine.AddPoint(new Point((float)monthNo * .5f, results[monthNo] + baseLine.Points[monthNo].Y));
            targetLine.AddPoint(new Point((float)monthNo * .5f + 1f, results[monthNo + 1] + baseLine.Points[monthNo + 1].Y));
          }
        }
      } else {
        if(baseLine == null) {
          for(int monthNo = 0; monthNo < results.Length; ++monthNo) {
            targetLine.AddPoint(new Point((float)monthNo, results[monthNo]));
            targetLine.AddPoint(new Point((float)monthNo + 1f, results[monthNo]));
          }
        } else {
          for(int monthNo = 0; monthNo < results.Length; ++monthNo) {
            targetLine.AddPoint(new Point((float)monthNo, results[monthNo] + baseLine.Points[monthNo].Y));
            targetLine.AddPoint(new Point((float)monthNo + 1f, results[monthNo] + baseLine.Points[monthNo + 1].Y));
          }
        }
      }

      ChartPrimitiveXY targetPolygon = ChartUtilities.LineDiffToPolygon(factory, baseLine, targetLine);
      color.A = (byte)(_alpha * color.A);
      targetPolygon.FillColor = color;
      targetPolygon.IsDashed = true;
      targetLine.IsHitTest = false;

      return new LineAndPolygon(targetLine, targetPolygon);
    }
コード例 #4
0
    /// <summary>
    /// Converts movements to a graphical line and polygon
    /// </summary>
    /// <param name="results"></param>
    /// <param name="color"></param>
    /// <param name="label"></param>
    /// <returns></returns>
    public static LineAndPolygon ConvertResultsToMovementLineAndPolygon(ChartControl factory, float[] results, Color color, string label) {
      // Create the Line
      ChartPrimitiveXY chartLine = factory.CreateXY();
      chartLine.LineColor = color;
      chartLine.Label = label;
      chartLine.LegendColor = color;
      chartLine.IsHitTest = true;

      for(int monthNo = 0; monthNo < results.Length; ++monthNo) {
        chartLine.AddSmoothHorizontalBar(new Point((float)monthNo + .5f, results[monthNo]));
      }

      // Create the polygon
      ChartPrimitiveXY polygon = ChartUtilities.ChartLineToBaseLinedPolygon(chartLine);
      color.A = (byte)(_alpha * color.A);
      polygon.FillColor = color;
      polygon.IsHitTest = false;

      return new LineAndPolygon(chartLine, polygon);
    }
コード例 #5
0
    public static void AddTestLines(ChartControl xyLineChart) {
      ChartControl factory = xyLineChart;
      // Add test Lines to demonstrate the control

      xyLineChart.Reset();

      double limit = 5;
      double increment = .05;

      // Create 3 normal lines
      ChartPrimitiveXY[] lines = new ChartPrimitiveXY[3];

      for(int lineNo = 0; lineNo < 3; ++lineNo) {
        ChartPrimitiveXY line = factory.CreateXY();

        // Label the lines
        line.Label = "Test Line " + (lineNo + 1).ToString();
        line.IsDashed = false;
        line.IsHitTest = true;
        line.LineThickness = 1.5;
        line.ShowPoints = true;

        line.AddPoint(0, 0);

        // Draw 3 sine curves
        for(double x = 0; x < limit + increment * .5; x += increment) {
          line.AddPoint(x, Math.Cos(x * Math.PI - lineNo * Math.PI / 1.5));
        }
        line.AddPoint(limit, 0);

        // Add the lines to the chart
        xyLineChart.AddPrimitive(line);
        lines[lineNo] = line;
      }

      // Set the line colors to Red, Green, and Blue
      lines[0].FillColor = Color.FromArgb(90, 255, 0, 0);
      lines[1].FillColor = Color.FromArgb(90, 0, 180, 0);
      lines[2].FillColor = Color.FromArgb(90, 0, 0, 255);

      // Set the line colors to Red, Green, and Blue
      lines[0].LineColor = Colors.Red;
      lines[1].LineColor = Colors.Green;
      lines[2].LineColor = Colors.Blue;

      lines[0].LegendColor = Colors.Red;
      lines[1].LegendColor = Colors.Green;
      lines[2].LegendColor = Colors.Blue;


      ChartPrimitiveHBar[] bars = new ChartPrimitiveHBar[3];

      // Set the line colors to Red, Green, and Blue
      Color[] barLineColors = new Color[]{
        Colors.Red,
        Colors.Green,
        Colors.Blue
      };

      Color[] barFillColors = new Color[]{
        Color.FromArgb(90, 255, 0, 0),
        Color.FromArgb(90, 0, 180, 0),
        Color.FromArgb(90, 0, 0, 255)
      };

      int colorIndex = 0;

      GridLineOverride gridLineOverride = new GridLineOverride(Orientation.Horizontal);
      gridLineOverride.Range = new Range<double>(-0.2 * (0 + 1) - 1 + 0.05, -0.2 * (2 + 1) - 1 - 0.05);

      for(int barNo = 0; barNo < 3; ++barNo) {
        ChartPrimitiveHBar bar = factory.CreateHBar(-0.2 * (barNo + 1) - 1, 0.05);

        gridLineOverride.AddLabel("Bar " + (barNo + 1).ToString(),-0.2 * (barNo + 1) - 1, Orientation.Horizontal);

        // Label the lines
        bar.IsDashed = false;
        bar.LineThickness = 1;
        bar.IsHitTest = true;
        bar.Label = "Test Bar " + (barNo + 1).ToString();

        colorIndex = barNo;
        for(double x = 0; x < 4 + barNo; x += 0.1 * (4 + barNo)) {
          bar.AddSegment(x, x+ 0.1 * (4 + barNo), barLineColors[colorIndex], barFillColors[colorIndex]);
          colorIndex = (colorIndex + 1) % 3;
        }
        // Add the lines to the chart
        xyLineChart.AddPrimitive(bar);
        bars[barNo] = bar;
      }

      xyLineChart.GridLineOverrides.Add(gridLineOverride);

      xyLineChart.Title = "Test Chart Title";
      xyLineChart.XAxisTitle = "Test Chart X Axis";
      xyLineChart.YAxisTitle = "Test Chart Y Axis";

      xyLineChart.RedrawPlotLines();
    }
コード例 #6
0
    /// <summary>
    /// Takes two lines and creates a polyon between them
    /// </summary>
    /// <param name="baseLine"></param>
    /// <param name="topLine"></param>
    /// <returns></returns>
    public static ChartPrimitiveXY LineDiffToPolygon(ChartControl factory, ChartPrimitiveXY baseLine, ChartPrimitiveXY topLine) {
      ChartPrimitiveXY polygon = factory.CreateXY();
      IList<Point> topLinePoints = topLine.Points;

      if(baseLine != null) {
        for(int pointNo = baseLine.Points.Count - 1; pointNo >= 0; --pointNo) {
          polygon.AddPoint(baseLine.Points[pointNo]);
        }
      } else {
        polygon.AddPoint(new Point(topLinePoints[topLinePoints.Count - 1].X, 0));
        polygon.AddPoint(new Point(0, 0));
      }

      for(int pointNo = 0; pointNo < topLinePoints.Count; ++pointNo) {
        polygon.AddPoint(topLinePoints[pointNo]);
      }

      polygon.FillColor = topLine.LineColor;

      return polygon;
    }
コード例 #7
0
 /// <summary>
 /// Gets ChartLines and ChartPolygons for the population line, and
 /// the target line.
 /// </summary>
 public static LineAndPolygon ConvertResultsToTargetLineAndPolygon(ChartControl factory, ChartPrimitive populationLine, float[] results, Color color, string label) {
   return ConvertResultsToTargetLineAndPolygon(factory, populationLine, results, color, label, null);
 }
コード例 #8
0
    /// <summary>
    /// Converts population level to a line and polygon using a ChartPrimitive as the baseline
    /// </summary>
    /// <param name="results"></param>
    /// <param name="color"></param>
    /// <param name="label"></param>
    /// <returns></returns>
    public static LineAndPolygon ConvertResultsToPopulationLineAndPolygon(ChartControl factory, float[] results, Color color, string label, ChartPrimitiveXY baseLine) {
      ChartPrimitiveXY populationLine = factory.CreateXY();
      populationLine.LineColor = color;
      populationLine.Label = label;
      populationLine.LegendColor = color;
      populationLine.IsHitTest = true;

      if(baseLine == null) {
        for(int monthNo = 0; monthNo < results.Length; monthNo += 2) {
          populationLine.AddPoint(new Point((float)monthNo * .5f, results[monthNo]));
          populationLine.AddPoint(new Point((float)monthNo * .5f + 1f, results[monthNo + 1]));
        }
      } else {
        for(int monthNo = 0; monthNo < results.Length; monthNo += 2) {
          populationLine.AddPoint(new Point((float)monthNo * .5f, results[monthNo] + baseLine.Points[monthNo].Y));
          populationLine.AddPoint(new Point((float)monthNo * .5f + 1f, results[monthNo + 1] + baseLine.Points[monthNo + 1].Y));
        }
      }

      ChartPrimitiveXY populationPolygon = ChartUtilities.LineDiffToPolygon(factory, baseLine, populationLine);
      color.A = (byte)(_alpha * color.A);
      populationPolygon.FillColor = color;
      populationPolygon.IsHitTest = false;

      return new LineAndPolygon(populationLine, populationPolygon);
    }
コード例 #9
0
 /// <summary>
 /// Converts population level to a line and polygon
 /// </summary>
 /// <param name="results"></param>
 /// <param name="color"></param>
 /// <param name="label"></param>
 /// <returns></returns>
 public static LineAndPolygon ConvertResultsToPopulationLineAndPolygon(ChartControl factory, float[] results, Color color, string label) {
   return ConvertResultsToPopulationLineAndPolygon(factory, results, color, label, null);
 }
コード例 #10
0
 public void SetChart(ChartControl chart)
 {
     _chart = chart;
     this.ResetChart();
 }
コード例 #11
0
 /// <summary>
 /// Gets ChartLines and ChartPolygons for the population line, and
 /// the target line.
 /// </summary>
 public static LineAndPolygon ConvertResultsToTargetLineAndPolygon(ChartControl factory, ChartPrimitive populationLine, float[] results, Color color, string label)
 {
     return(ConvertResultsToTargetLineAndPolygon(factory, populationLine, results, color, label, null));
 }
コード例 #12
0
 /// <summary>
 /// Converts population level to a line and polygon
 /// </summary>
 /// <param name="results"></param>
 /// <param name="color"></param>
 /// <param name="label"></param>
 /// <returns></returns>
 public static LineAndPolygon ConvertResultsToPopulationLineAndPolygon(ChartControl factory, float[] results, Color color, string label)
 {
     return(ConvertResultsToPopulationLineAndPolygon(factory, results, color, label, null));
 }