I have an UltraChart of type LineChart. I create a number of NumericTime series and add them to the chart without problemm, but I can't seem to add legend items. Is this because I'm putting NumericTimeSeries in a LineChart?
Infragistics.UltraChart.Resources.Appearance.NumericTimeSeries gwElevSeries = new Infragistics.UltraChart.Resources.Appearance.NumericTimeSeries();
foreach (DataRow gwElevDr in qrySelectGwMonRecords)
{
gwElevSeries.Points.Add(new Infragistics.UltraChart.Resources.Appearance.NumericTimeDataPoint(System.DateTime.Parse(gwElevDr.ItemArray[2].ToString()), System.Double.Parse(gwElevDr.ItemArray[8].ToString()), String.Format("{0:M/d/yyyy}", gwElevDr.ItemArray[2]), false));
}
chartGwData.ChartType = Infragistics.UltraChart.Shared.Styles.ChartType.LineChart;
chartGwData.Series.Add(gwElevSeries);
chartGwData.Visible = true;
If anyone can help me place the NumericTimeSeries legend item into the LineChart legend it would be much appreciated. Thanks in advance. Ruben
Hi,
Make sure that you have set:
series.Label = "Series 1";
and the legend is visible:
this.ultraChart1.Legend.Visible = true;
Ok thanks much. Now how do I get the line's appearance in the legend to look like it does in the UltraChart?
This is now it looks in the code:
grndElSeries = numTimeSeriesDict["grndElSeries"];
grndElSeries.Label = "Ground Elev. (ft)";
grndElSeries.PEs.Add(new PaintElement(Color.DarkKhaki));
LineAppearance grndElLineApp = new LineAppearance();
grndElLineApp.Thickness = 10;
grndElLineApp.LineStyle.DrawStyle = LineDrawStyle.Solid;
chartGwData.LineChart.ChartComponent.Series.Add(grndElSeries);
chartGwData.LineChart.LineAppearance.Add(grndElLineApp);
But when I do this i get a thick line on the chart but a thin line in the Legend. How do I get the legend line customized?? Thanks VERY much.
You can change the legend border with:
this.ultraChart1.Legend.BorderColor = Color.DarkKhaki;
this.ultraChart1.Legend.BorderThickness = 10;
this.ultraChart1.Legend.BorderStyle = LineDrawStyle.Solid;
Thanks for you response.
Maybe I wasn't clear on what it was I'm trying to do. I don't want to change the appearance of the Legend, I want to change the appearance of the legend items. In other words, the LineChart elements inside the borders of the legend. So I've replaced the Legend from your previous code with LegendItem. I know this isn't correct syntax, but it's essentially what I'm trying to do.
this.chartGwData.LegendItem.Color = Color.DarkKhaki;
this.chartGwData.LegendItem.Thickness = 10;
this.chartGwData.LegendItem.Style = LineDrawStyle.Solid;
Best Regards, Ruben
Ok,
Try using this code:
this.ultraChart1.ChartDrawItem += new ChartDrawItemEventHandler(ultraChart1_ChartDrawItem);
…
private void ultraChart1_ChartDrawItem(object sender, ChartDrawItemEventArgs e)
if (string.IsNullOrEmpty(e.Primitive.Path) ||
e.Primitive.Path.EndsWith("Legend") == false)
return;
Polyline polyline = e.Primitive as Polyline;
if (polyline == null)
polyline.PE.Fill = Color.Red;
polyline.PE.StrokeWidth = 10;
Great! Thanks so much. What if I wanted to apply different PEs to each NumericTimeSeries that is in the graph?
Just don’t change the Fill of the polyline. It has the same color as the line chart.
//polyline.PE.Fill = Color.Red;
Thanks again!
That works pretty well. I guess what I'm looking for is to be able to customize more than just StrokeWidth. For instance, if I wanted one series to appear in the legend as StrokeWidth = 4, LineStyle = Dashed and another series to appear as StrokeWidth = 2, LineStyle = Dotted. It appears that the only variation that is allowed is the default Color value of the series.
Thanks very much for your help.