反转折线图的方向

时间:2015-04-29 00:44:20

标签: c# charts

我尝试了许多内容,例如设置Right to Left或弄乱IsReversed的{​​{1}}属性,但没有去。有什么建议吗?

很抱歉缺少信息,我认为它只是我忽略的图表属性中的某个位置。无论如何,我正在制作一个自定义图表,现在线条从左到右,但我需要它向反方向移动

need to draw the fricking thing from right to left

我想另一种说法是如何添加从右到左的点?

1 个答案:

答案 0 :(得分:3)

如果你想要反转x轴,你需要做的就是

private void button1_Click(object sender, EventArgs e)
{
    ChartArea CA = chart1.ChartAreas[0];
    CA.AxisX.IsReversed = true;
}

之前和之后:

enter image description here enter image description here

如果要将y轴保持在左侧,请使用:

private void button2_Click(object sender, EventArgs e)
{
    ChartArea CA = chart1.ChartAreas[0];
    CA.AxisY2.Enabled = AxisEnabled.True;
    CA.AxisY.Enabled = AxisEnabled.False;
    CA.AxisX.IsReversed = true;
}

enter image description here

如果您在评论时只想在左侧添加DataPoints,则可以这样做:

Series S = chart1.Series[0];
DataPoint dp = new DataPoint(dp.XValue, dp.YValues[0]);
S.Points.Insert(0, dp);

这可能会慢一点,但它最终会与Adding它们一样有效。您可能需要查看this post,其中DataPoints插入Points集合中的各个位置。

请注意,Points通常像数组一样访问,但实际上类型为DataPointCollection,因此可以随时添加和删除以及许多其他操作。

一个常见用途是从左侧移除点以创建像示波器一样的“移动”图表。

相关问题