简体   繁体   中英

How to show the marker points in line graph using c#

I am using Line graph in my application and is working fine. I tried to draw the marker points in line graph,but the marker points are not displaying. In line chart marker properties, I have chosen markerSize as 5, markerStyle as Circle, MarkerColor as blue.Refer my code below.

 series1.Name = "Series1";
 series1.IsVisibleInLegend = false;
 series1.IsXValueIndexed = true;
 series1.XValueType = ChartValueType.Time;
 series1.YAxisType = AxisType.Primary;
 series1.ChartType = SeriesChartType.Line;
 this.chart1.Series.Add(series1);

I don't see how the Markers can show up from your code.

You need to set a non-default MarkerStyle :

 series1.MarkerStyle = MarkerStyle.Circle;

If you use the debugger on that line you can see how the default is None !

Of course you will want to play with all other marker relates series properties , which all inherited from the DataPointCustomProperties

You are using ChartType.Line which is fine. Note that FastLine does not display markers!

If you only want to show some Markers simply style them for each point:

S1.Points[8].MarkerStyle = MarkerStyle.Triangle;
S1.Points[8].MarkerSize = 22;
S1.Points[8].MarkerColor = Color.Red;

I suggest getting each of your points, looping through them and adding each one. I noticed you want to set a name so I just created a counter then appended an integer value to the end of 'ser', name how you please.

Dim counter as int = 0;
foreach (Series ser in chart.Series)
{
   ser.Name = "ser" & counter + 1;
   ser.IsVisibleInLegend = false;
   ser.IsXValueIndexed = true;
   ser.XValueType = ChartValueType.Time;
   ser.YAxisType = AxisType.Primary;
   ser.ChartType = SeriesChartType.Line;
   this.chart1.Series.Add(ser);
   counter += 1;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM