当您有一个所有x坐标均为零的线系列时,图表将有助于重新组织点,以便x坐标为1、2、3等。这很好,但是,在我只有一个点的情况下在系列中,该点的x坐标确实为零,我想覆盖这种“有用的”行为,以使该点以其真实的x坐标(即0.0)而不是替代的x坐标(即1.0)。

有谁知道如何做到这一点?我怀疑这是显而易见的。

编辑1

谢谢jstreet。您的示例就是我想要的,但是当我运行这段代码时,我得到了这个输出!有什么不同?

void MainFormLoad(object sender, EventArgs e)
{
    Random r = new Random();
    chart1.Series["Series1"].ChartType= SeriesChartType.Line;
    chart1.Series["Series1"].IsXValueIndexed= false;

    chart1.Series["Series2"].ChartType= SeriesChartType.FastLine;
    chart1.Series["Series2"].IsXValueIndexed= false;

    chart1.Series["Series3"].ChartType= SeriesChartType.Point;
    chart1.Series["Series3"].IsXValueIndexed= false;

    chart1.Series["Series4"].ChartType= SeriesChartType.FastPoint;
    chart1.Series["Series4"].IsXValueIndexed= false;

    chart1.Series["Series5"].ChartType= SeriesChartType.Line;
    chart1.Series["Series5"].IsXValueIndexed= true;

    chart1.Series["Series6"].ChartType= SeriesChartType.FastLine;
    chart1.Series["Series6"].IsXValueIndexed= true;

    chart1.Series["Series7"].ChartType= SeriesChartType.Point;
    chart1.Series["Series7"].IsXValueIndexed= true;

    chart1.Series["Series8"].ChartType= SeriesChartType.FastPoint;
    chart1.Series["Series8"].IsXValueIndexed= true;

    for (int i = 0; i < 10; i++)
    {
        chart1.Series["Series1"].Points.AddXY(0, r.Next(70, 80));
        chart1.Series["Series2"].Points.AddXY(0, r.Next(60, 70));
        chart1.Series["Series3"].Points.AddXY(0, r.Next(50, 60));
        chart1.Series["Series4"].Points.AddXY(0, r.Next(40, 50));
        chart1.Series["Series5"].Points.AddXY(0, r.Next(30, 40));
        chart1.Series["Series6"].Points.AddXY(0, r.Next(20, 30));
        chart1.Series["Series7"].Points.AddXY(0, r.Next(10, 20));
        chart1.Series["Series8"].Points.AddXY(0, r.Next(0, 10));
    }
}


c# - 在x坐标等于0的序列中绘制点-LMLPHP

编辑2

按照要求...

private void InitializeComponent()
{
    System.Windows.Forms.DataVisualization.Charting.ChartArea chartArea1 = new System.Windows.Forms.DataVisualization.Charting.ChartArea();
    System.Windows.Forms.DataVisualization.Charting.Legend legend1 = new System.Windows.Forms.DataVisualization.Charting.Legend();
    System.Windows.Forms.DataVisualization.Charting.Series series1 = new System.Windows.Forms.DataVisualization.Charting.Series();
    System.Windows.Forms.DataVisualization.Charting.Series series2 = new System.Windows.Forms.DataVisualization.Charting.Series();
    System.Windows.Forms.DataVisualization.Charting.Series series3 = new System.Windows.Forms.DataVisualization.Charting.Series();
    System.Windows.Forms.DataVisualization.Charting.Series series4 = new System.Windows.Forms.DataVisualization.Charting.Series();
    System.Windows.Forms.DataVisualization.Charting.Series series5 = new System.Windows.Forms.DataVisualization.Charting.Series();
    System.Windows.Forms.DataVisualization.Charting.Series series6 = new System.Windows.Forms.DataVisualization.Charting.Series();
    System.Windows.Forms.DataVisualization.Charting.Series series7 = new System.Windows.Forms.DataVisualization.Charting.Series();
    System.Windows.Forms.DataVisualization.Charting.Series series8 = new System.Windows.Forms.DataVisualization.Charting.Series();
    this.chart1 = new System.Windows.Forms.DataVisualization.Charting.Chart();
    ((System.ComponentModel.ISupportInitialize)(this.chart1)).BeginInit();
    this.SuspendLayout();
    //
    // chart1
    //
    chartArea1.Name = "ChartArea1";
    this.chart1.ChartAreas.Add(chartArea1);
    this.chart1.Dock = System.Windows.Forms.DockStyle.Fill;
    legend1.Name = "Legend1";
    this.chart1.Legends.Add(legend1);
    this.chart1.Location = new System.Drawing.Point(0, 0);
    this.chart1.Name = "chart1";
    this.chart1.Palette = System.Windows.Forms.DataVisualization.Charting.ChartColorPalette.Chocolate;
    series1.ChartArea = "ChartArea1";
    series1.Legend = "Legend1";
    series1.Name = "Series1";
    series2.ChartArea = "ChartArea1";
    series2.Legend = "Legend1";
    series2.Name = "Series2";
    series3.ChartArea = "ChartArea1";
    series3.Legend = "Legend1";
    series3.Name = "Series3";
    series4.ChartArea = "ChartArea1";
    series4.Legend = "Legend1";
    series4.Name = "Series4";
    series5.ChartArea = "ChartArea1";
    series5.Legend = "Legend1";
    series5.Name = "Series5";
    series6.ChartArea = "ChartArea1";
    series6.Legend = "Legend1";
    series6.Name = "Series6";
    series7.ChartArea = "ChartArea1";
    series7.Legend = "Legend1";
    series7.Name = "Series7";
    series8.ChartArea = "ChartArea1";
    series8.Legend = "Legend1";
    series8.Name = "Series8";
    this.chart1.Series.Add(series1);
    this.chart1.Series.Add(series2);
    this.chart1.Series.Add(series3);
    this.chart1.Series.Add(series4);
    this.chart1.Series.Add(series5);
    this.chart1.Series.Add(series6);
    this.chart1.Series.Add(series7);
    this.chart1.Series.Add(series8);
    this.chart1.Size = new System.Drawing.Size(504, 397);
    this.chart1.TabIndex = 0;
    this.chart1.Text = "chart1";
    //
    // MainForm
    //
    this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
    this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
    this.ClientSize = new System.Drawing.Size(504, 397);
    this.Controls.Add(this.chart1);
    this.Name = "MainForm";
    this.Text = "TestChart";
    this.Load += new System.EventHandler(this.MainFormLoad);
    ((System.ComponentModel.ISupportInitialize)(this.chart1)).EndInit();
    this.ResumeLayout(false);
}

最佳答案

AddXY始终尊重您的意愿。如果您使所有点x = 0,那么您将得到:

    private void Form1_Load(object sender, EventArgs e)
    {
        Random r = new Random();

        for (int i = 0; i < 10; i++)
            chart1.Series["Series1"].Points.AddXY(i, r.Next(0, 50));

        for (int i = 0; i < 10; i++)
            chart1.Series["Series2"].Points.AddXY(0, r.Next(50, 100));

        chart1.Series["Series3"].Points.AddXY(0, 0);
    }


c# - 在x坐标等于0的序列中绘制点-LMLPHP

编辑:设计器生成的代码:

    private void InitializeComponent()
    {
        System.Windows.Forms.DataVisualization.Charting.ChartArea chartArea1 = new System.Windows.Forms.DataVisualization.Charting.ChartArea();
        System.Windows.Forms.DataVisualization.Charting.Legend legend1 = new System.Windows.Forms.DataVisualization.Charting.Legend();
        System.Windows.Forms.DataVisualization.Charting.Series series1 = new System.Windows.Forms.DataVisualization.Charting.Series();
        System.Windows.Forms.DataVisualization.Charting.Series series2 = new System.Windows.Forms.DataVisualization.Charting.Series();
        System.Windows.Forms.DataVisualization.Charting.Series series3 = new System.Windows.Forms.DataVisualization.Charting.Series();
        this.chart1 = new System.Windows.Forms.DataVisualization.Charting.Chart();
        ((System.ComponentModel.ISupportInitialize)(this.chart1)).BeginInit();
        this.SuspendLayout();
        //
        // chart1
        //
        chartArea1.AxisX.MajorGrid.LineColor = System.Drawing.Color.DarkGray;
        chartArea1.AxisX.MajorGrid.LineDashStyle = System.Windows.Forms.DataVisualization.Charting.ChartDashStyle.Dot;
        chartArea1.AxisY.MajorGrid.LineColor = System.Drawing.Color.DarkGray;
        chartArea1.AxisY.MajorGrid.LineDashStyle = System.Windows.Forms.DataVisualization.Charting.ChartDashStyle.Dot;
        chartArea1.Name = "ChartArea1";
        this.chart1.ChartAreas.Add(chartArea1);
        this.chart1.Dock = System.Windows.Forms.DockStyle.Fill;
        legend1.Alignment = System.Drawing.StringAlignment.Center;
        legend1.Docking = System.Windows.Forms.DataVisualization.Charting.Docking.Top;
        legend1.Name = "Legend1";
        this.chart1.Legends.Add(legend1);
        this.chart1.Location = new System.Drawing.Point(0, 0);
        this.chart1.Name = "chart1";
        series1.ChartArea = "ChartArea1";
        series1.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line;
        series1.Legend = "Legend1";
        series1.MarkerStyle = System.Windows.Forms.DataVisualization.Charting.MarkerStyle.Circle;
        series1.Name = "Series1";
        series2.ChartArea = "ChartArea1";
        series2.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line;
        series2.Legend = "Legend1";
        series2.MarkerStyle = System.Windows.Forms.DataVisualization.Charting.MarkerStyle.Square;
        series2.Name = "Series2";
        series3.ChartArea = "ChartArea1";
        series3.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line;
        series3.Legend = "Legend1";
        series3.MarkerSize = 8;
        series3.MarkerStyle = System.Windows.Forms.DataVisualization.Charting.MarkerStyle.Diamond;
        series3.Name = "Series3";
        this.chart1.Series.Add(series1);
        this.chart1.Series.Add(series2);
        this.chart1.Series.Add(series3);
        this.chart1.Size = new System.Drawing.Size(782, 353);
        this.chart1.TabIndex = 0;
        this.chart1.Text = "chart1";
        //
        // Form1
        //
        this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 16F);
        this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
        this.ClientSize = new System.Drawing.Size(782, 353);
        this.Controls.Add(this.chart1);
        this.Name = "Form1";
        this.Text = "Form1";
        this.Load += new System.EventHandler(this.Form1_Load);
        ((System.ComponentModel.ISupportInitialize)(this.chart1)).EndInit();
        this.ResumeLayout(false);

    }

关于c# - 在x坐标等于0的序列中绘制点,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/32843768/

10-09 15:50