We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Help w/ Line Chart

Hi, I was wondering if you can help me out. I would like to make a line chart that would display the following data:

Apple: 25
Orange: 45
Peach: 75
Grape: 15
Pear: 112

I would also like each item to have a different color. Can you please provide an example how I can do this.

Thanks


5 Replies

SR SubhaSheela R Syncfusion Team January 9, 2008 06:53 AM UTC

Hi Michael,

Thank you for using for Syncfusion products.

We can give different colors to each of the items by passing the values for label name, color, font and ChartValueType parameters to the PrimaryXAxis's Label method. Please refer to the code snipept given below:

this.chartControl1.PrimaryXAxis.ValueType = ChartValueType.Custom;
this.chartControl1.PrimaryXAxis.TickLabelsDrawingMode = ChartAxisTickLabelDrawingMode.UserMode;
this.chartControl1.PrimaryXAxis.Labels.Clear();
this.chartControl1.PrimaryXAxis.Labels.Add(new ChartAxisLabel("Apple", Color.Crimson, new Font("Monospace", 11), 0, "", ChartValueType.Custom));
this.chartControl1.PrimaryXAxis.Labels.Add(new ChartAxisLabel("Orange", Color.Blue, new Font("Monospace", 11), 1, "", ChartValueType.Custom));
this.chartControl1.PrimaryXAxis.Labels.Add(new ChartAxisLabel("Peach", Color.LightBlue, new Font("Monospace", 11), 2, "", ChartValueType.Custom));
this.chartControl1.PrimaryXAxis.Labels.Add(new ChartAxisLabel("Grape", Color.GreenYellow, new Font("Monospace", 11), 3, "", ChartValueType.Custom));
this.chartControl1.PrimaryXAxis.Labels.Add(new ChartAxisLabel("Pear", Color.Crimson, new Font("Monospace", 11), 4, "", ChartValueType.Custom));


Kindly have a look into the simple sample available in the link below that illustrates the same:

http://websamples.syncfusion.com//samples/ Chart.Windows//F70888/main.htm

Please let me if you have any questions.

Regards,
Subhasheela R





SR SubhaSheela R Syncfusion Team January 9, 2008 06:59 AM UTC

Hi Michael,

Sorry for the broken link. Here is the link:

http://websamples.syncfusion.com/samples/Chart.Windows/F70888/main.htm

Regards,
Subhasheela R




MS Michael Sabin January 9, 2008 03:36 PM UTC

Sorry, when I said line chart, I really meant Bar Chart. Your example did help a little, but I would like to set a different color for each bar (not the label at the bottom). I tried to create a different Series for each object but that doesn't work correctly.

Thanks



SR SubhaSheela R Syncfusion Team January 10, 2008 06:14 AM UTC

Hi Michael,

Sorry for the inconvenience caused.

We can give different colors to each of the bars by handling ChartPrepareStyleInfoHandlerEvent. Please refer to the code snippet given below:

void series_PrepareStyle(object sender, ChartPrepareStyleInfoEventArgs args)
{
ChartSeries series = sender as ChartSeries;
if (series != null)
{
if (args.Index == 0)
args.Style.Interior = new Syncfusion.Drawing.BrushInfo(Color.Red);
else if (args.Index == 1)
args.Style.Interior = new Syncfusion.Drawing.BrushInfo(Color.Green);
else if (args.Index == 2)
args.Style.Interior = new Syncfusion.Drawing.BrushInfo(Color.Blue);
else if (args.Index == 3)
args.Style.Interior = new Syncfusion.Drawing.BrushInfo(Color.Yellow);
else if (args.Index == 4)
args.Style.Interior = new Syncfusion.Drawing.BrushInfo(Color.Aqua);
}
}


Kindly have a look into the sample available in the link below and let me know if it helps:

http://websamples.syncfusion.com//samples/Chart.Windows//F70888FollowUp/main.htm

Regards,
Subhasheela R





MS Michael Sabin January 10, 2008 02:36 PM UTC

Thank you, that is just what I wanted.


Loader.
Live Chat Icon For mobile
Up arrow icon