Cluster Bar Graph (how to have common labels on x axis)


https://www.nevron.com/Forum/Topic9620.aspx
Print Topic | Close Window

By Theodore Kang - 8 Years Ago
Example:  distance travelled by transportation type

With the sample data below, how does one achieve a common category for the transportation type such that the bars for each series are side by side and commonly labelled.

Series 1:

Ndatapoint(10, "Car")
Ndatapoint(20, "Bus")
Ndatapoint(40, "Plane")

Series 2:

Ndatapoint(30, "Car")
Ndatapoint(30, "Bus")
Ndatapoint(50, "Plane")


By Nevron Support - 8 Years Ago
Hi,
The following code shows how to create a cluster bar with custom x category labels:
   NChart chart = nChartControl1.Charts[0];

    NBarSeries bar1 = new NBarSeries();

    bar1.Values.Add(10);
    bar1.Values.Add(20);
    bar1.Values.Add(30);

    chart.Series.Add(bar1);

    NBarSeries bar2 = new NBarSeries();

    bar2.MultiBarMode = MultiBarMode.Clustered;
    bar2.Values.Add(30);
    bar2.Values.Add(30);
    bar2.Values.Add(40);

    chart.Series.Add(bar2);

    NOrdinalScaleConfigurator scaleX = chart.Axis(StandardAxis.PrimaryX).ScaleConfigurator as NOrdinalScaleConfigurator;

    scaleX.AutoLabels = false;
    scaleX.Labels.Add("Car");
    scaleX.Labels.Add("Bus");
    scaleX.Labels.Add("Plane");

Hope this helps - let us know if you meet any problems.
By Theodore Kang - 8 Years Ago

Thanks for the quick response on this, that worked.
I have another question.  Some of the labels are rather long in length.  I saw the example that used a linearscaleconfigurator.  Is there a way to wrap the text for the custom labels for the ordinalscaleconfigurator?

By Nevron Support - 8 Years Ago
Hi Theodore,

Yes - you need to replace the value scale label style of the configurator (which is the default) to range:
    NRangeScaleLabelStyle labelStyle = new NRangeScaleLabelStyle();
    labelStyle.TickMode = RangeLabelTickMode.None;
    scaleX.LabelStyle = labelStyle;

That way labels will wrap to their respective category range.