none
Solid colored lines on a chart RRS feed

  • Question

  • This is an extract from a Visual Basic 6 project.

    I would like to do the same in Visual Studio. I do not know how to fill several series of data on a chart. Is there a way?

    Saturday, February 1, 2020 3:38 PM

Answers

All replies

  • Verg,

    That depends on exactly what you mean and how picky you are about it. :)

    You should be able to do what you want.

    For your general use the Samples project link below is very helpful documentation you open in Visual Studio and run. It is c# but it is easy to open in visual studio and run just like a vb project. The app is docs for the chart with pictures and example code. About the best there is. Then you just keep hunting and practicing for ideas.

    Samples environments for microsoft chart Controls

     

    Below is a simple example that uses the spline area fill type and draws two point series.

    I don't know if you can find two colors for positive and negative (red blue) built in but you can use two series and plot one pos and one neg etc lots of possibilities.

     

     

    Public Class Form2
        Private Sub Form2_Load(sender As Object, e As EventArgs) Handles Me.Load
    
            With Chart1.ChartAreas(0)
                .AxisX.Title = "Time"
                .AxisX.MajorGrid.LineColor = Color.LightBlue
                .AxisX.Minimum = 0
                .AxisX.Maximum = 15
                .AxisX.Interval = 2
                .AxisY.Title = "Energy"
                .AxisY.MajorGrid.LineColor = Color.LightGray
            End With
    
            Chart1.Series.Clear()
            Chart1.Series.Add("2Pi")
            Chart1.Series.Add("4Pi")
    
            With Chart1.Series("2Pi")
                .IsVisibleInLegend = False
                .BorderColor = Color.Green
                .BorderWidth = 2
                .Color = Color.FromArgb(50, Color.Green)
                .ChartType = DataVisualization.Charting.SeriesChartType.SplineArea
                For x As Double = 0 To 2 * 6.28 Step 0.627
                    .Points.AddXY(x, Math.Sin(x))
                Next
            End With
    
            With Chart1.Series("4Pi")
                .IsVisibleInLegend = False
                .BorderColor = Color.Red
                .BorderWidth = 2
                .Color = Color.FromArgb(50, Color.Red)
                .ChartType = DataVisualization.Charting.SeriesChartType.SplineArea
                For x As Double = 0 To 2 * 6.28 Step 0.313
                    .Points.AddXY(x, 0.5 * Math.Sin(2 * x))
                Next
            End With
        End Sub
    End Class

    Saturday, February 1, 2020 11:15 PM
  • Thanks again tommytwotrain.

    Enzo

    Sunday, February 2, 2020 10:26 AM
  • Thanks again tommytwotrain.

    Enzo

    You are welcome.

    BTW you should mark the post with the answer in it as the answer (ie my example post).

    Feel free to ask if you have additional questions. We are normally not sure exactly what you want. However I am sure you can figure most of it out.

    You should also mark your previous log chart question as answered.

    :)

    Sunday, February 2, 2020 11:13 AM