|
Dual Y-Axis with Multi-Bar layer |
Posted by Ramesh on Oct-15-2020 19:07 |
|
Hi Support Team,
i have two dataSet with having 2 records in each and i want to draw Dual Y-Axis chart,
but the value is getting override.
below is the code:-
BarLayer layer = c.addBarLayer2(Chart.Side);
if (col[seqno].MeasureName == "Titrant Chart")
{
for (int jj = 0; jj < datseriesYAxis1.Count; jj++)
{
//put each data set into its own layer
layer = c.addBarLayer2(Chart.Side);
for (int jjj = 0; jjj < datseriesYAxis1.Count; jjj++)
{
layer.addDataGroup();
if (jj != jjj)
layer.addDataSet(null);
else
{
if (jj == 0)
{
layer.addDataSet(datseriesYAxis2[jj], colors[jj], col[seqno].Legends[jj] ?? "Legend").setDataSymbol(Chart.CircleSymbol, 5);
layer.addDataSet(datseriesYAxis1[jj], colors[jj], col[seqno].Legends[jj] ?? "Legend").setDataSymbol(Chart.CircleSymbol, 5);
layer.setBarWidth(35);
}
if (jj == 1)
{
layer.addDataSet(datseriesYAxis1[jj], colors[jj], col[seqno].Legends[jj] ?? "Legend").setDataSymbol(Chart.CircleSymbol, 5);
layer.addDataSet(datseriesYAxis2[jj], colors[jj], col[seqno].Legends[jj] ?? "Legend").setDataSymbol(Chart.CircleSymbol, 5);
}
}
}
if (jj == 1)
{
c.yAxis2().setTitle(measure[0].MeasureName + " (mL/LT)", "Arial Bold Italic", 10, 000000);
layer.setBarWidth(35);
layer.setUseYAxis2();
//curAxis = c.addAxis(Chart.Right, 0);
//layer.setUseYAxis(curAxis);
}
}
}
Thanks
Ramesh |
Re: Dual Y-Axis with Multi-Bar layer |
Posted by Ramesh on Oct-15-2020 19:44 |
|
Please find the screenshot
|
Re: Dual Y-Axis with Multi-Bar layer |
Posted by Ramesh on Oct-15-2020 19:45 |
|
Please find the screenshot |
Re: Dual Y-Axis with Multi-Bar layer |
Posted by Peter Kwan on Oct-16-2020 01:50 |
|
Hi Ramesh,
Without your actual data, it is hard for me to notice any error in the chart. Would you mint to clarify what is the error?
If I assume datseriesYAxis1.Count = 2, then by manually tracing your code, I found that your code is equivalent to:
layer = c.addBarLayer2(Chart.Side);
layer.addDataGroup();
layer.addDataSet(datseriesYAxis2[0], colors[0], col[seqno].Legends[0] ?? "Legend").setDataSymbol(Chart.CircleSymbol, 5);
layer.addDataSet(datseriesYAxis1[0], colors[0], col[seqno].Legends[0] ?? "Legend").setDataSymbol(Chart.CircleSymbol, 5);
layer.addDataGroup();
layer.setBarWidth(35);
layer.addDataSet(null);
layer = c.addBarLayer2(Chart.Side);
layer.addDataGroup();
layer.addDataSet(null);
layer.addDataGroup();
layer.addDataSet(datseriesYAxis1[1], colors[1], col[seqno].Legends[1] ?? "Legend").setDataSymbol(Chart.CircleSymbol, 5);
layer.addDataSet(datseriesYAxis2[1], colors[1], col[seqno].Legends[1] ?? "Legend").setDataSymbol(Chart.CircleSymbol, 5);
c.yAxis2().setTitle(measure[0].MeasureName + " (mL/LT)", "Arial Bold Italic", 10, 000000);
layer.setBarWidth(35);
layer.setUseYAxis2();
As mentioned in the ChartDirector documentation, the addDataGroup is only used in the Chart.Stack. So we can ignore that line in your code, which uses Chart.Side.
Your code contains 2 bar layers. Each layer contains 3 data sets in Chart.Side layout, which means each x-positions contains 3 bars. In each layer, one of the data sets is null, so one of the bars will not be visible. The middle bars of the two layers overlap, so one of them may hide the other (depending on their data values).
If the above is not what you want, please modify your code to rearrange the bars to meet your requirements. For 4 data series, it is easier to directly write sequential code, than to write nested loops with a lot of "if/else" conditions.
Regards
Peter Kwan |
|