Hi,
I'm using a composite chart in my application and adding a composite Legend to chart in the fillscenegraph event. However the problem is that the legend items are not getting displayed initially and when I resize the chart or change the window layout, then the legend becomes visible.
My chart control is on top of a user control which is added to a windows form.Also, find attached the screen shot of the same.
Please find below the sample code for adding the legend:
void
m_Chart_FillSceneGraph(object sender, Infragistics.UltraChart.Shared.Events.FillSceneGraphEventArgs e) {
if (tempCollection.Count > 0){
e.SceneGraph.AddRange(tempCollection.ToArray());
foreach (Primitive prim in tempCollection)
{
UpdatePrimitives(prim,primitveRangeMap[prim]);
}
if (m_Parent.DisplayLegend)
AddLegend();
private void AddLegend(){
if (m_HistLayerAppearance != null){
if (this.m_Chart.CompositeChart.Legends.Count < 1)
CompositeLegend myLegend = new CompositeLegend();
myLegend.ChartLayers.Add(m_HistLayerAppearance);
myLegend.Bounds =
new Rectangle(75, 2, 20, 10);
myLegend.BoundsMeasureType = MeasureType.Percentage;
myLegend.PE.ElementType =
PaintElementType.SolidFill;
myLegend.PE.Fill =
Color.White;
myLegend.PE.FillStopColor =
myLegend.Border.CornerRadius = 5;
myLegend.Border.Thickness = 1;
myLegend.LabelStyle.FontColor =
Color.Black;
myLegend.LabelStyle.FontSizeBestFit =
true;
myLegend.LabelStyle.WrapText =
this.m_Chart.CompositeChart.Legends.Add(myLegend);
Regards,
Uday
Sorry, but I'm not entirely sure what you're trying to accomplish and why you're using FillSceneGraph event to do it. First, let me advise against setting properties on your chart instance inside FillSceneGraph. Doing so will likely cause the chart to repaint and FillSceneGraph will be called repeatedly from within itself. Use FillSceneGraph to add shapes (primitives) directly onto the scenegraph only. I would suggest a different approach, but i'm not sure what your goal is.
Max,
Thanks for your reply. I am just trying to add a composite legend to my chart and make it customizable(like user can change the location and font style etc from a dialog).
The problem is that the legend items are not getting displayed initially(as shown in the screen shots attached). I am actually adding the legend in the method where I create the histogram series but it still doesnt show. hence, I tried to add it in the fillscenegraph event. Please find below the piece of code where I'm creating the histogram series and adding it to the composite chart. I dont understand where am I going wrong.
protected void UpdateChart() { try { ISeries[] allSeries = CreateHistogramSeries();
if (m_ChartArea == null) { m_ChartArea = new ChartArea(); m_ChartArea.Key = "chartArea1"; m_Chart.CompositeChart.ChartAreas.Add(m_ChartArea); }
if ((m_AxisX_Value == null) || (m_AxisY_Value == null)) { m_AxisX_Label = CreateAxisX_Label(); m_ChartArea.Axes.Add(m_AxisX_Label); m_AxisX_Value = CreateAxisX_Value(); m_ChartArea.Axes.Add(m_AxisX_Value); m_AxisY_Value = CreateAxisY_Value(); m_ChartArea.Axes.Add(m_AxisY_Value); }
if (m_HistLayerAppearance == null) { m_HistLayerAppearance = new ChartLayerAppearance(); m_HistLayerAppearance.Key = "chartLayer1"; m_HistLayerAppearance.AxisXKey = "AxisX_Label"; m_HistLayerAppearance.AxisYKey = "AxisY_Value"; m_HistLayerAppearance.ChartAreaKey = "chartArea1"; m_HistLayerAppearance.ChartType = ChartType.StackColumnChart;
m_HistLayerAppearance.Series.AddRange(allSeries); m_Chart.CompositeChart.ChartLayers.Add(m_HistLayerAppearance); } else { m_HistLayerAppearance.Series.Clear(); m_HistLayerAppearance.Series.AddRange(allSeries); }
if (m_AxisLayerAppearance == null) { m_AxisLayerAppearance = new ChartLayerAppearance(); m_AxisLayerAppearance.Key = "chartLayer2"; m_AxisLayerAppearance.AxisXKey = "AxisX_Value"; m_AxisLayerAppearance.AxisYKey = "AxisY_Value"; m_AxisLayerAppearance.ChartAreaKey = "chartArea1"; m_AxisLayerAppearance.ChartType = ChartType.LineChart;
m_Chart.CompositeChart.ChartLayers.Add(m_AxisLayerAppearance); }
if (m_Parent.DisplayLegend) AddLegend(); m_Chart.Tooltips.Display = TooltipDisplay.MouseClick; m_Chart.InvalidateLayers(); } catch (Exception ex) { PetrelLogger.ErrorBox(ex.StackTrace); } }
private void AddLegend() { if (m_HistLayerAppearance != null) { if (this.m_Chart.CompositeChart.Legends.Count < 1) { CompositeLegend myLegend = new CompositeLegend(); myLegend.ChartLayers.Add(m_HistLayerAppearance); myLegend.Bounds = new Rectangle(75, 2, 20, 10); myLegend.BoundsMeasureType = MeasureType.Percentage; myLegend.PE.ElementType = PaintElementType.SolidFill; myLegend.PE.Fill = Color.White; myLegend.PE.FillStopColor = Color.White; myLegend.Border.CornerRadius = 5; myLegend.Border.Thickness = 1; myLegend.LabelStyle.FontColor = Color.Black; myLegend.LabelStyle.FontSizeBestFit = true; myLegend.LabelStyle.WrapText = true; this.m_Chart.CompositeChart.Legends.Add(myLegend); } } }