charting markers not appearing on line

2019-07-04 16:52发布

问题:

So I'm using Windows Forms Chart to generate graphs containing several lines that can create some clutter on the graph and need something to differentiate them other than color. There are too many points to using dotted or dashed lines as there is no observable difference between that and a continuous line. So what I'm hoping to do is to get markers with various shapes to show up on the lines like in Excel, for instance. Right now I'm have it coded like this

myChart.Series["MySeries"].ChartType = SeriesChartType.FastLine;
myChart.Series["MySeries"].MarkerStyle = MarkerStyle.Diamond;

What this does is put a diamond in the legend over that line, but it doesn't put diamonds on the actual line that is in the chart itself. Changing the marker size doesn't make a difference, unfortunately, and neither does changing the marker color. Is there a way to get that to happen. Thanks for reading, and any help you have.

EDIT: Heres the relevant code. Its data is held in a class that is the value-peice of a dictionary. The class contains a list of doubles.

public void Charter(Color colorOfLine)
{
    double xValue;
    double yValue;

    myChart.Series.Add("MySeries");
    myChart.Series["MySeries"].ChartType.FastLine;
    myChart.Series["MySeries"].ChartArea = "ChartArea1";
    myChart.Series["MySeries"].Color = colorOfLine;

    myChart.Series["MySeries"].MarkerStyle = MarkerStyle.Diamond;
    myChart.Series["MySeries"].MarkerColor = Color.Black;
    myChart.Series["MySeries"].MarkerSize = 5;
    myChart.Series["MySeries"].MarkerBoarderColor = Color.DeepPink;

    foreach (KeyValuePair<int, MyClass> Pair in MyDictionary)
    {
        xValue = Pair.Value.MyClassList[0];
        yValue = Pair.Value.MyClassList[1];

        myChart.Series["MySeries"].Points.AddXY(xValue, yValue);
    }

}

I should add that I've played around with the MarkerStep, and MarkerBoarderWidth as well, all to no benefit. The issue seems to be that the marker simply isn't appearing on the actual lines in the chart itself. Also I'm using Visual Studio 2010 Express for what its worth. Thanks again for reading.

回答1:

Use Line. Don't use FastLine. FastLine won't generate markers for you.

myChart.Series["MySeries"].ChartType = SeriesChartType.Line 


回答2:

Set the MarkerSize to something bigger:

myChart.Series["MySeries"].MarkerSize = 4;

ETA:

You may also need to set the color of the marker:

myChart.Series["MySeries"].MarkerColor = Color.Blue;
myChart.Series["MySeries"].Color = Color.Blue;