簡體   English   中英

使用C#在Winform中折線圖中的多個系列

[英]Multiple Series in Line chart in Winform using C#

我是Winform Application新手。 我正在嘗試實現一個line chart ,該line chart具有多個series並具有一個checkedListbox以選擇particular series

碼:

if (tbROI.SelectedTab == tbROI.TabPages["tbPageROIPoint"])
            {
                //If all ROI TAB
                myIndex = GetMyChartIndex(mSeries, chartPointROI); // 4 for Point ROI tab

                m_PointDataCounter++;
                if (m_PointDataCounter > 15)
                {
                    if (myIndex > 5)
                    {
                        chartPointROI.Series[mSeries].Points.RemoveAt(0);
                        m_PointDataCounter--;
                    }
                }

                if (cbListPOI.GetItemChecked(ROIIndex))
                {
                    chartPointROI.Series[mSeries].Points.AddXY(timestring, mData);

                    chartPointROI.ResetAutoValues();
                }
            }

使用此代碼,我將數據放在chart control X-axis代表時間, Y-axis代表數據。

Initailly當我選擇listbox的任何項目時,系列從左側開始,但是在某個時間之后,如果我再開始一個系列,它也將從左側開始,但是我想從X軸上表示的當前時間開始。

當我在一段時間后停止任何series時,如果我再次開始同一series我希望在系列中留出一定的間隔,以便可以清楚地看到該系列已停止。

就我而言,系列總是從左側開始。 如果我停止任何系列並重新開始,它將在停止的地方繼續。

提前致謝

編輯:

在此處輸入圖片說明

這表明

這是一個有關如何刪除一些DataPoints以及如何還原它們的示例。

注意間隙中的平線。 如果要“去除”該線以最好的顏色,則最后一點透明; 我為此添加了注釋代碼。

List<DataPoint> marked = new List<DataPoint>();
int markedStartIndex = -1;

private void button1_Click(object sender, EventArgs e)
{
    // I create a testperiod to remove
    DateTime dt0 = DateTime.Now.AddMonths(2);
    DateTime dt1 = dt0.AddHours(123);
    DateTime dt2 = dt0.AddHours(173);

    // convert to doubles:
    double startPeriod = dt1.ToOADate();
    double endPeriod = dt2.ToOADate();

    // short reference
    Series s = chart1.Series[0];
    // select the points in the period. pick your border conditions!
    marked = s.Points.Cast<DataPoint>()
                     .Where(x => x.XValue > startPeriod && x.XValue < endPeriod)
                     .ToList();

    if (marked.Count < 1) return;

    // remember where we started to remove
    markedStartIndex = s.Points.IndexOf(marked.First()); 
    foreach (DataPoint dp in marked) s.Points.Remove(dp);

    // Optionally 'hide' the gap line
    //if (markedStartIndex > 0) s.Points[markedStartIndex].Color = Color.Transparent;
}

使它們返回的代碼將它們插入正確的位置,然后清除這些點。:

private void button2_Click(object sender, EventArgs e)
{
    Series s = chart1.Series[0];
    // optionally re-color the gap-line 
    //if (markedStartIndex > 0) s.Points[markedStartIndex].Color = s.Color;

    foreach (DataPoint dp in marked) s.Points.Insert(markedStartIndex++, dp);
    marked.Clear();
}

結果存在透明的差距:

在此處輸入圖片說明

您也可以將間隙用紅色上色,並存儲多個點。 為此,您必須存儲起點,並確保重新插入時管理多個期間!

作為實際刪除點的替代方法,您還可以選擇簡單地將它們着色為透明。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM