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
385
Combined chart, Column and line
posted

Hi, I want to make a chart that has one column series and one line series in same chart. I also want to use the same two axis(x,y).

 Lets say I have this dataset:

Col1 | Col2  | Col3
3400 | 4322 | 1
2300 | 1000 | 2
5994 | 1400 | 3

I want column 3 to be my x axis labels(stringSmile i know )

Column 1 is to be shown in my chart as columns

Column 2 is to be shown in my chart as a line.

 Col 1 is budget amount, col2 is realAmount and col 3 is period (month)

The result Im after should look exacly like a Column Line Chart, but not have the same functionality.

Hope someone can help me.

I tried adding two different YXseries, but that didn't work. Maybe layering is what I need.

I'm getting really frustrated with the lack of documentation. Sure, there is plenty info on data members, but what I REALLY need is simple how to guides or examples that show how to use the different datamembers and functionsAngry.

THX

Geir

 

Parents
  • 26458
    Offline posted
    I'm not sure why you can't use ColumnLine chart type, but here's how you would use a composite chart. You cannot use the same x axis for column and line layers because they need different values for SetLabelAxisType property (one is GroupBySeries, the other is Continuous). Here's an example:

    DataTable dt = new DataTable();
    dt.Columns.Add(
    "col1", typeof(int));
    dt.Columns.Add(
    "col2", typeof(int));
    dt.Columns.Add(
    "col3", typeof(string));
    dt.Rows.Add(
    new object[ {3400, 4322, "1"});
    dt.Rows.Add(
    new object[ {2300, 1000, "2"});
    dt.Rows.Add(
    new object[ {5994, 1400, "3"});

    this.ultraChart1.ChartType = ChartType.Composite;
    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;
    xAxisLine.DataType =
    AxisDataType.String;
    xAxisLine.SetLabelAxisType =
    SetLabelAxisType.ContinuousData;
    yAxis.DataType =
    AxisDataType.Numeric;
    yAxis.Labels.ItemFormat =
    AxisItemLabelFormat.DataValue;
    area.Axes.Add(xAxisColumn);
    area.Axes.Add(xAxisLine);
    area.Axes.Add(yAxis);

    NumericSeries seriesColumn = new NumericSeries();
    seriesColumn.Data.DataSource = dt;
    seriesColumn.Data.LabelColumn =
    "col3";
    seriesColumn.Data.ValueColumn =
    "col1";
    NumericSeries seriesLine = new NumericSeries();
    seriesLine.Data.DataSource = dt;
    seriesLine.Data.LabelColumn =
    "col3";
    seriesLine.Data.ValueColumn =
    "col2";
    this.ultraChart1.Series.AddRange(new ISeries[ { seriesLine, seriesColumn });

    ChartLayerAppearance columnLayer = new ChartLayerAppearance();
    columnLayer.AxisX = xAxisColumn;
    columnLayer.AxisY = yAxis;
    columnLayer.ChartArea = area;
    columnLayer.ChartType =
    ChartType.ColumnChart;
    columnLayer.Series.Add(seriesColumn);

    ChartLayerAppearance lineLayer = new ChartLayerAppearance();
    lineLayer.AxisX = xAxisLine;
    lineLayer.AxisY = yAxis;
    lineLayer.ChartArea = area;
    lineLayer.ChartType =
    ChartType.LineChart;
    lineLayer.Series.Add(seriesLine);

    this.ultraChart1.CompositeChart.ChartLayers.Add(columnLayer);
    this.ultraChart1.CompositeChart.ChartLayers.Add(lineLayer);

Reply Children