Chart for .NET / User's Guide / Chart / Horizontal Charts

In This Topic
    Horizontal Charts
    In This Topic

    Very often it is necessary to display some charting types like Bar, Float Bar, Line etc. in a horizontal projection. The easiest way to create horizontal charts is with the help of the predefined chart styles of the NChart object. The following figure displays horizontal bar charts with left and right alignment.




    Figure 1.

    The chart layout is controlled with the help of the PredefinedChartStyle property of the NChart object. This property is actually a helper which affects the chart 3D-view as well as the alignments of the axes titles and texts. It accepts values from the enumeration type PredefinedChartStyle . The members of the enum are:

    Vertical - the standard layout of the chart, which is set as default.
    HorizontalLeft - horizontal layout with left alignment.
    HorizontalRight - horizontal layout with right alignment.

    The following code creates a left aligned horizontal bar chart:

    C#
    Copy Code
    NCartesianChart chart = (NCartesianChart)chartControl.Charts[0];
    chart.PredefinedChartStyle = PredefinedChartStyle.HorizontalLeft;
    
    NBarSeries bar = (NBarSeries)chart.Series.Add(SeriesType.Bar);
    bar.Values.Add(5.0);
    bar.Values.Add(3.0);
    bar.Values.Add(7.0);
    bar.Values.Add(6.0);
    chartControl.Refresh();
    
    Visual Basic
    Copy Code
    Dim chart As NCartesianChart = chartControl.Charts(0)
    chart.PredefinedChartStyle = PredefinedChartStyle.HorizontalLeft
    
    Dim bar As NBarSeries = chart.Series.Add(SeriesType.Bar)
    bar.Values.Add(5.0)
    bar.Values.Add(3.0)
    bar.Values.Add(7.0)
    bar.Values.Add(6.0)
    chartControl.Refresh()
    

    You can achieve similar results by manually modifying the chart 3D-view and axis properties. For example you can use the SetPredefinedProjection method of the NProjection object with one of the following values to create a left aligned chart:

    PredefinedProjection.OrthogonalHorizontalLeft
    PredefinedProjection.OrthogonalHalfHorizontalLeft
    PredefinedProjection.PerspectiveHorizontalLeft

    Furthermore you will have to modify the HorzAlign and VertAlign properties of the axis texts and axis titles for each visible axis. Since this might be a labour-consuming task, it is generally recommended to use the PredefinedChartStyle property for overall setup and after that fine-tune the axes and 3D-view if this is required.

     Related Examples
    Windows forms: Chart Gallery\Bar\Horizontal Bar
    Windows forms: Chart Gallery\Float Bar\Horizontal Float Bar
    See Also