Andres
Andres

Reputation: 2899

MS Chart color and legends in Winforms

I use a Microsoft Chart in one of my forms. I selected a Pie Chart.

Then, in runtime, I assign the values and legends I need like this:

{
    double[] yValues = { valor_pendiente, valor_gest_judicial, valor_cancelado };
    string[] xNames = { "Pendientes", "Gest. Judic.", "Cancelado" };

    chart1.Series[0].Points.DataBindXY(xNames, yValues);
    Color[] colores = new Color[] { Barra_azul, Color.Orange, Color.LimeGreen };
    chart1.PaletteCustomColors = colores;
}

Ok, now I have two questions:

1: Is there any way to hide the legends when the value is so small or zero? Because graphically, I does not look OK.

enter image description here

Gest. Judic. does not have any value there and stills shows.

Is there any other way to show legends?

1st issue has been solved

Also, the second question:

Can I Use gradients instead of colors (instead of using that array of colors)? If I can, how can I do it?

Upvotes: 1

Views: 2262

Answers (1)

endofzero
endofzero

Reputation: 1820

The Series class lets you set a BackGradientStyle for gradient direction. Then set BackSecondaryColor to change the fade-in color of the gradient.

chart1.Series[0].BackGradientStyle = GradientStyle.DiagonalRight;
chart1.Series[0].BackSecondaryColor = Color.Cyan;

You can also set the gradient for each DataPoint in the chart to give them each a custom gradient:

chart1.Series[0].Points[0].BackGradientStyle = GradientStyle.DiagonalRight;
chart1.Series[0].Points[0].Color = Color.Red;
chart1.Series[0].Points[0].BackSecondaryColor = Color.Brown;

Note that this doesn't work if you have the 3D effect enabled, so it must be turned off.

chart1.ChartAreas[0].Area3DStyle.Enable3D = false;

Upvotes: 2

Related Questions