Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
465
Legend Items Not Displaying
posted

I've included code and an image below.  Now for the questions.  Notice that the rectangle for the legend is displaying, but not the labels.  Can you see the problem in my code?  My tired eyes can't.  Also, the first datapoint for the line chart is NULL, but I don't want it to plot as a zero value.  I tried to define the LineChart.NullHandling as "DontPlot" but that did not work.  Any ideas on this one?  Thanks again!

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
 
using Infragistics.UltraChart.Shared.Styles;
using Infragistics.UltraChart.Resources.Appearance;
using Infragistics.UltraChart.Core.Layers;
 
namespace InfragraphicsChart
{
    public partial class WebForm1 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
 
          
    DataTable tbldata = new DataTable();
string strConn = System.Configuration.ConfigurationManager.ConnectionStrings["MCISSQLConnection"].ConnectionString;
SqlConnection sTransConn = new SqlConnection(strConn);
SqlCommand sTransCmd = new SqlCommand();
sTransCmd.Connection = sTransConn;
sTransConn.Open();
sTransCmd.CommandText = "MCIS_PortalPart_KPI_Graph '" + "Stanislaus" + "', " + "5";
SqlDataReader objTransReader = sTransCmd.ExecuteReader();
// Add the fields to the data table to populate.
tbldata.Columns.Add("day", typeof(string));
tbldata.Columns.Add("Actual", typeof(int));
tbldata.Columns.Add("Plan", typeof(int));
tbldata.Columns.Add("Moving Average", typeof(int));
// Add the rows.
while (objTransReader.Read())
{
    tbldata.Rows.Add(new object[] { objTransReader["NameShort"].ToString(), objTransReader["Transports_System"], objTransReader["Transports_System_Plan"], objTransReader["Transports_System_MovAvg"] });
 
}
 
// close all SQL objects.
sTransConn.Close();
sTransConn.Dispose();
sTransCmd.Dispose();
objTransReader.Close();
objTransReader.Dispose();
 
//return tbldata;
 
          
this.ultraChart1.ChartType = ChartType.Composite;
//this.ultraChart1.Data.SwapRowsAndColumns = true;
PaintElement peLightGreen = new PaintElement(System.Drawing.Color.LightGreen);
PaintElement peLIghtBlue = new PaintElement(System.Drawing.Color.LightBlue);
PaintElement peBlue = new PaintElement(System.Drawing.Color.Blue);
ChartArea area = new ChartArea();
this.ultraChart1.CompositeChart.ChartAreas.Add(area);
AxisItem xAxisColumn = new AxisItem(this.ultraChart1, AxisNumber.X_Axis);
 
AxisItem xAxisLine = new AxisItem(this.ultraChart1, AxisNumber.X_Axis);
AxisItem yAxis = new AxisItem(this.ultraChart1, AxisNumber.Y_Axis);
xAxisColumn.DataType = AxisDataType.String;
xAxisColumn.SetLabelAxisType = SetLabelAxisType.GroupBySeries;
xAxisColumn.Labels.ItemFormat = AxisItemLabelFormat.ItemLabel;
xAxisColumn.Margin.Near.Value = 5;
xAxisColumn.Margin.Far.Value = 5;
xAxisLine.DataType = AxisDataType.String;
xAxisLine.SetLabelAxisType = SetLabelAxisType.ContinuousData;
xAxisLine.Margin.Near.Value = 5;
xAxisLine.Margin.Far.Value = 5;
yAxis.DataType = AxisDataType.Numeric;
yAxis.Labels.ItemFormat = AxisItemLabelFormat.DataValue;
yAxis.RangeType = AxisRangeType.Custom;
yAxis.RangeMin = 0;
yAxis.RangeMax = 100;
 
area.Axes.Add(xAxisColumn);
area.Axes.Add(xAxisLine);
area.Axes.Add(yAxis);
 
NumericSeries seriesColumn = new NumericSeries();
seriesColumn.Data.DataSource = tbldata;
seriesColumn.Data.LabelColumn = "day";
seriesColumn.Data.ValueColumn = "Actual";
      
seriesColumn.PEs.Add(peLIghtBlue);
 
NumericSeries seriesColumn2 = new NumericSeries();
seriesColumn2.Data.DataSource = tbldata;
seriesColumn2.Data.LabelColumn = "day";
seriesColumn2.Data.ValueColumn = "Plan";
seriesColumn2.PEs.Add(peLightGreen);
 
NumericSeries seriesLine = new NumericSeries();
seriesLine.Data.DataSource = tbldata;
seriesLine.Data.LabelColumn = "day";
seriesLine.Data.ValueColumn = "Moving Average";
seriesLine.PEs.Add(peBlue);
            
 
//this.ultraChart1.Series.AddRange(new Infragistics.UltraChart.Data.Series.ISeries[] { seriesLine, seriesColumn, seriesColumn2 });
this.ultraChart1.Series.Add(seriesLine);
this.ultraChart1.Series.Add(seriesColumn);
this.ultraChart1.Series.Add(seriesColumn2);
ChartLayerAppearance columnLayer = new ChartLayerAppearance();
columnLayer.AxisX = xAxisColumn;
columnLayer.AxisY = yAxis;
columnLayer.ChartArea = area;
columnLayer.ChartType = ChartType.ColumnChart;
columnLayer.Series.Add(seriesColumn);
columnLayer.Series.Add(seriesColumn2);
columnLayer.SwapRowsAndColumns = true;
 
ChartLayerAppearance lineLayer = new ChartLayerAppearance();
lineLayer.AxisX = xAxisLine;
lineLayer.AxisY = yAxis;
lineLayer.ChartArea = area;
lineLayer.ChartType = ChartType.LineChart;
lineLayer.Series.Add(seriesLine);
 
            
CompositeLegend myLegend = new CompositeLegend();
myLegend.ChartLayers.Add(columnLayer);
myLegend.ChartLayers.Add(lineLayer);
myLegend.Bounds = new System.Drawing.Rectangle(10, 80 ,80, 15);
myLegend.BoundsMeasureType = MeasureType.Percentage;
myLegend.Visible = true;
myLegend.PE.FillOpacity = 128;
myLegend.Border.CornerRadius = 10;
myLegend.LabelStyle.Font = new System.Drawing.Font("Times New Roman", 10);
 
this.ultraChart1.CompositeChart.Legends.Add(myLegend);
 
this.ultraChart1.LineChart.NullHandling = (NullHandling)System.Enum.Parse(typeof(NullHandling), "DontPlot");   
 
this.ultraChart1.CompositeChart.ChartLayers.Add(columnLayer);
this.ultraChart1.CompositeChart.ChartLayers.Add(lineLayer);
 
this.ultraChart1.ColumnChart.SeriesSpacing = 0;
         
 
 
        }
    }
}
 
Parents
No Data
Reply
  • 28496
    Offline posted

    make sure you set the Label property of each series, otherwise there will be nothing to display in the legend.

     

    also, since this is a composite chart, you need to set the NullHandling property like this:

    ((LineChartAppearance)lineLayer.ChartTypeAppearance).NullHandling = DontPlot

Children