多个Y轴标签/标题彼此重叠

时间:2020-01-27 12:26:46

标签: c# overlap teechart

我正在使用以下代码显示图表的多个Y轴。当任何轴标签值的位数超过3位时,该轴标签/标题将与其他轴标签重叠(如图所示)。

int leftIndex = 0, rightIndex = 0;
int relativePosition = 0;                 
foreach (Steema.TeeChart.Axis axis in this.tChart.Axes.Custom)
    {                       
    axis.Visible = true;

    axis.PositionUnits = Steema.TeeChart.PositionUnits.Pixels;

    axis.RelativePosition = 0 - (axis.OtherSide ? rightIndex++ : leftIndex++) * 60;

    relativePosition = relativePosition + (axis.AxisRect().Width + 60);

    }

1 个答案:

答案 0 :(得分:0)

您应该能够通过稍微修改计算中的常量来使图表正确呈现,例如

TChart _tChart;
public Form1()
{
    InitializeComponent();

    _tChart = new TChart();
    _tChart.Dock = DockStyle.Fill;

    _tChart.Series.Add(typeof(Line)).FillSampleValues();
    _tChart.Series.Add(typeof(Line)).FillSampleValues();
    _tChart.Series.Add(typeof(Line)).FillSampleValues();

    _tChart.Series[0].YValues.Value = _tChart.Series[2].YValues.Value.Select(x => x * 100).ToArray();

    _tChart.Header.Text = Utils.Version;
    _tChart[0].CustomVertAxis = _tChart.Axes.Custom.Add();
    _tChart[0].CustomVertAxis.Title.Text = "Axis One Title";
    _tChart[0].CustomVertAxis.Title.Angle = 90;

    _tChart[1].CustomVertAxis = _tChart.Axes.Custom.Add();
    _tChart[1].CustomVertAxis.Title.Text = "Axis Two Title";
    _tChart[1].CustomVertAxis.Title.Angle = 90;

    _tChart[2].CustomVertAxis = _tChart.Axes.Custom.Add();
    _tChart[2].CustomVertAxis.Title.Text = "Axis Three Title";
    _tChart[2].CustomVertAxis.Title.Angle = 90;

    int leftIndex = 0, rightIndex = 0;

    for (int i = 0; i < this._tChart.Axes.Custom.Count; i++)
    {
        var axis = this._tChart.Axes.Custom[i];
        axis.Visible = true;
        axis.PositionUnits = Steema.TeeChart.PositionUnits.Pixels;
        axis.RelativePosition = 0 - (axis.OtherSide ? rightIndex++ : leftIndex++) * (i == 1 ? 80: 70);
    }


    _tChart.Panel.MarginLeft = 30;
    this.Controls.Add(_tChart);
}

这给了我什么: enter image description here

相关问题