c# - 多个 Y 轴标签/标题相互重叠
问题描述
我使用以下代码显示图表的多个 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);
}
解决方案
您应该能够通过稍微修改计算中的常数来正确渲染图表,例如
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);
}
推荐阅读
- cloud - 在 Grafana 中显示 GCloud Billing
- html - 电子邮件签名中的图像
- python - Android adb sendevent 没有正确执行事件
- android - 无法创建到运行热点的 Android 设备的套接字连接
- javascript - Update Chart when add/remove records Ext JS
- html - 带类的元素内的最后一个带类的元素的 CSS 选择器
- jquery - 在 iOS 上的 Safari 中滚动 Bootstrap 导航栏不起作用
- java - W/Firestore:[CustomClassMapper]:Android 类没有设置器/字段
- biztalk - 无法加载文件或程序集
- c# - CRM 插件跟踪日志 - 仅用于沙盒模式的日志