我想用带有多条曲线的列表框中的多个图表填充Zedgraph窗格。我的方法当前填充了这些曲线,但它们都具有相同的颜色和符号类型。有关为每个添加的曲线分配不同颜色的任何建议吗?
public void btnMakePlt_Click(object sender, EventArgs e)
{
try
{
// Initialize graph window
GraphPane myPane = zgcMain.GraphPane;
// clear plt
myPane.CurveList.Clear();
zgcMain.Refresh();
// Use this foreach to plot curves in the Selected Curves Listbox
foreach (var item2 in lstSelectedCurves.Items)
{
// turn CurveName into String
txtCurve = item2.ToString();
//Invoke IPmathCurveMethods, populate List
PointPairList list = new PointPairList();
double[] CurveDataVal = PlotIPdataStuffValues(txtCurve);
double[] CurveDataDepth = PlotIPdataStuffDepths(txtCurve);
for (int i = 0; i < CurveDataVal.Length; i++)
{
double z1 = CurveDataDepth[i];
double z2 = CurveDataVal[i];
if (z2 <= 0)
{
z2 = double.NaN;
}
//add to list
list.Add(z2, z1);
}
LineItem myCurve = myPane.AddCurve(txtCurve, list, Color.Red, SymbolType.None);
zgcMain.Refresh();
}
}
catch (Exception ex)
{
MessageBox.Show("Error making your plot \n" + ex.Message + "\n" + ex.StackTrace);
}
}
答案 0 :(得分:0)
您可以设置您选择的颜色列表并在foreach循环中使用它,也可以使用zedgraph中提供的自动颜色旋转器,如下所示。请注意,颜色范围有限制,它会循环回来。
// Use this foreach to plot curves in the Selected Curves Listbox
var colorRotator = new ColorSymbolRotator();
var currentColor = Color.Black;
foreach (var item2 in lstSelectedCurves.Items)
{
// turn CurveName into String
txtCurve = item2.ToString();
//Invoke IPmathCurveMethods, populate List
PointPairList list = new PointPairList();
double[] CurveDataVal = PlotIPdataStuffValues(txtCurve);
double[] CurveDataDepth = PlotIPdataStuffDepths(txtCurve);
for (int i = 0; i < CurveDataVal.Length; i++)
{
double z1 = CurveDataDepth[i];
double z2 = CurveDataVal[i];
if (z2 <= 0)
{
z2 = double.NaN;
}
//add to list
list.Add(z2, z1);
}
LineItem myCurve = myPane.AddCurve(txtCurve, list, currentColor, SymbolType.None);
currentColor = colorRotator.NextColor;
zgcMain.Refresh();
}
如果您想重复一定数量的颜色更改并重复使用,则可以随时重置颜色旋转器。我认为默认情况下第一种颜色是黑色(索引= 0)。
colorRotator.NextColorIndex = 0;