c# - Multiple Series in Line chart in Winform using C#
问题描述
I am new in Winform Application
. I am trying to implement a line chart
which have multiple series
and have a checkedListbox
to select the particular series
.
Code:
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();
}
}
Using this code I am putting the data on the chart control
.
The X-axis
representing Time and Y-axis
representing Data.
Initailly when I select any item of listbox
the series starts from left side, but after sometime if I start one more series it will also start from left side but I want to start that from the current time which is representing on X-axis.
And when I stop any series
after some time if I again start the same series
I want to some gap in the series so that it can be clearly seen that series is been stopped.
In my case the series always starts from left side. And if I stop any series and start that again It will continue where it stopped.
Thanks in advance
EDIT:
It is showing that
解决方案
Here is an example of how to remove a few DataPoints
and also of how to restore them.
Note the flat line in the gap. If you want to 'remove' that line best color the last point transparent; I have added commented code for this.
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;
}
The code to bring them back inserts them at the right spot and then clears the points.:
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();
}
Result with a transparent gap:
You could also color the gap in red and also store more than one set of points; for this you would have to store the starting points as well as make sure to manage multiple periods when you re-insert them!
As an alternative to actually removing the points you could also choose to simply color them transparent..
推荐阅读
- sql - 联合(或)输入sql
- python - 在pyqt5中选择按钮并打开其他按钮并重置其他按钮
- javascript - 使用纯 JavaScript 将文本变量复制到剪贴板
- oracle-adf - 如何在 Oracle ADF 的工具栏上设置按钮的对齐方式
- kubernetes - Keycloak 和 istio 服务网格无法工作
- python - 彩条上的手动刻度
- elasticsearch - 带有 AWS-ES 的 Kafka Elasticsearch 连接器:JestElasticsearchClient 中的 NullPointerException
- java - 有没有办法从 Netbeans 11.1 上的现有 Java 代码自动生成类图?
- ruby-on-rails - 迁移在部署过程中中止并出现错误:PG::UndefinedTable: 错误:关系“播放列表”不存在
- json - 如何实现这个角树组件异步数据代码?