Page 1 of 1

different marks with different arrowlengths

Posted: Thu Mar 13, 2014 2:11 am
by 17365127
Hi, I'm using Xamarin to build an android project.

I have a chart with candle series, I want each mark of candles has different arrowlength.
How can it be done?

Re: different marks with different arrowlengths

Posted: Thu Mar 13, 2014 3:47 pm
by narcis
Hello,

You can do that setting custom marks positions like this:

Code: Select all

    private Steema.TeeChart.TChart tChart1;
	
    protected override void OnCreate(Bundle bundle)
    {
      base.OnCreate(bundle);
      InitializeChart();      
    }

    private Steema.TeeChart.Styles.Candle candle1;
	
    private void InitializeChart()
    {
      tChart1 = new Steema.TeeChart.TChart(this);

      tChart1.Aspect.View3D = false;
      tChart1.Zoom.Style = Steema.TeeChart.ZoomStyles.Classic;

      candle1 = new Steema.TeeChart.Styles.Candle(tChart1.Chart);
      candle1.FillSampleValues(5);
      candle1.Marks.Visible = true;

      tChart1.BeforeDrawSeries += tChart1_BeforeDrawSeries;

      SetContentView(tChart1);
    }

    void tChart1_BeforeDrawSeries(object sender, Graphics3D g)
    {
      RepositionMarks(candle1);
    }

    const int offsetFactor = 30;

    private void RepositionMarks(Steema.TeeChart.Styles.Candle candle)
    {

      for (int i = 0; i < tChart1[0].Count; i++)
      {
        SeriesMarks.Position pos = new SeriesMarks.Position();
        pos.Custom = true;
        TextShape item = tChart1[0].Marks.Items[i];

        CalculateMarkPosition(item, tChart1[0].YValues[i].ToString(tChart1[0].ValueFormat), tChart1[0].CalcXPos(i), tChart1[0].CalcYPos(i), (offsetFactor * i), pos);

        tChart1[0].Marks.Positions.Add(pos);
      }
    }

    private void CalculateMarkPosition(TextShape shape, string aText, int xPos, int yPos, int offset, SeriesMarks.Position position)
    {
      Graphics3D g = tChart1.Chart.Graphics3D;
      int tmpW = Utils.Round(g.TextWidth(aText));

      if (tChart1[0].Marks.Symbol.Visible)
      {
        tmpW += g.FontHeight;
      }

      tmpW += Utils.Round(g.TextWidth(Texts.CharForHeight) * 0.5);
      int tmpH = g.FontHeight;

      if (shape.Pen.Visible)
      {
        int tmpWidth = 2 * Utils.Round(shape.Pen.Width);
        tmpW += tmpWidth;
        tmpH += tmpWidth;
      }
      else tmpH++;

      position.Width = tmpW;
      position.Height = tmpH;
      position.ArrowTo.X = xPos;
      position.ArrowTo.Y = yPos + offset;
      position.ArrowFrom.X = xPos;
      position.ArrowFrom.Y = yPos + tmpH;
      position.LeftTop.X = position.ArrowTo.X - (tmpW / 2);
      position.LeftTop.Y = position.ArrowTo.Y - tmpH;

      if (tChart1[0].Marks.Symbol.Visible)
      {
        tChart1[0].Marks.Symbol.Top = position.LeftTop.Y + 2;
        tChart1[0].Marks.Symbol.Left = position.LeftTop.X + 2;
        tChart1[0].Marks.Symbol.Bottom = tChart1[0].Marks.Symbol.Top + g.FontHeight - 4;
        tChart1[0].Marks.Symbol.Right = tChart1[0].Marks.Symbol.Left + g.FontHeight - 4;
      }
    }