none
How to get color from a DataPoint in MSChart component? RRS feed

  • Frage

  • Hello,

    i need the colors of the DataPoints in a series wich have a palette. If i try to get the color it allways is black.

    This is a part oft the code:
    Me.PortfolioChart.Series("Produkte").Points.DataBind(Me.ProduktPortFolioDataBS, "X", "Y", "Tooltip=Name")
    Me.PortfolioChart.Series("Produkte").IsValueShownAsLabel = True
    
    
    For Each dp As DataVisualization.Charting.DataPoint In Me.PortfolioChart.Series("Produkte").Points
    Me.PortfolioChart.Legends("Legend1").CustomItems.Add(dp.Color, dp.ToolTip)
    Next
    Has anyone an idea?

    Thanks!
    Donnerstag, 12. November 2009 11:16

Antworten

  • Hello Andreas,

    If you want to set colors for individual DataPoints, you would have to loop through them and set the colors individually.


    for (int i = 0; i < Me.PortfolioChart.Series[0].Points.Count; i++)
                {
                    System.Windows.Forms.DataVisualization.Charting.DataPoint point = Me.PortfolioChart.Series[0].Points[i];
                    double high = point.YValues[0];
                    double low = point.YValues[1];
                    double open = point.YValues[2];
                    double close = point.YValues[3];
    
                    if(/*Condition here*/)
                    {
                        point.Color = Color.Green;
                    }
                    else
                    {
                        point.Color = Color.Red;
                    }
                }


    Please see also the following link. Maybe it can help you further.

    Samples Environment for Microsoft Chart Controls  à http://code.msdn.microsoft.com/mschart

    Best regards,

    Robert

    Dienstag, 24. November 2009 11:38
    Moderator

Alle Antworten

  • Hello Andreas,

    First: You are in the German Part of MSDN Forums .  There are no MSChart Component Forums here. Next Time post here:

    http://social.msdn.microsoft.com/Forums/en-US/MSWinWebChart/threads


    >>Me.PortfolioChart.Legends("Legend1").CustomItems.Add(dp.Color, dp.ToolTip)

    Second: dp.Color is a Propertie. You must have a Get or Set Method

    Regards
    Oliver
    Donnerstag, 12. November 2009 16:14
  • Hello Oliver,

    First: I have tried to do this but this forum was not avalable to post.

    Second: I dont under stand your answer. I know that color is a propertie but it is not set if i use a palette (Excel in my case). In need a way to write the color to the legend because i have to identify the points in the series wich is  bubble type.

    Andreas
    Montag, 16. November 2009 08:34
  • Hello Andreas,

    If you want to set colors for individual DataPoints, you would have to loop through them and set the colors individually.


    for (int i = 0; i < Me.PortfolioChart.Series[0].Points.Count; i++)
                {
                    System.Windows.Forms.DataVisualization.Charting.DataPoint point = Me.PortfolioChart.Series[0].Points[i];
                    double high = point.YValues[0];
                    double low = point.YValues[1];
                    double open = point.YValues[2];
                    double close = point.YValues[3];
    
                    if(/*Condition here*/)
                    {
                        point.Color = Color.Green;
                    }
                    else
                    {
                        point.Color = Color.Red;
                    }
                }


    Please see also the following link. Maybe it can help you further.

    Samples Environment for Microsoft Chart Controls  à http://code.msdn.microsoft.com/mschart

    Best regards,

    Robert

    Dienstag, 24. November 2009 11:38
    Moderator