32f3fc0923bb980d145313b65f8b469b3e26a0a0
FAQ/How-do-I-set-only-one-Y-axis-in-a-chart.md
| ... | ... | @@ -14,22 +14,50 @@ If you would like to override this feature and display only one chart, you can u |
| 14 | 14 | |
| 15 | 15 | ### C# (Dundas engine) |
| 16 | 16 | ```csharp |
| 17 | +//Code to hide the right Y axis: |
|
| 17 | 18 | public override void CustomizeDundasChart(object chart, Hashtable properties, Type chartType) |
| 18 | 19 | { |
| 19 | - if (chartType.FullName != "Izenda.AdHoc.DundasBarChart") |
|
| 20 | - return; |
|
| 21 | - Dundas.Charting.WebControl.Chart dchart = chart as Dundas.Charting.WebControl.Chart; |
|
| 22 | - if (dchart == null) |
|
| 23 | - return; |
|
| 24 | - |
|
| 25 | - if (dchart.Series.Count > 1) |
|
| 26 | - dchart.Series[1].YAxisType = Dundas.Charting.WebControl.AxisType.Primary; |
|
| 20 | + if (chartType.FullName != "Izenda.AdHoc.DundasBarChart") |
|
| 21 | + return; |
|
| 22 | + |
|
| 23 | + Dundas.Charting.WebControl.Chart dchart = chart as Dundas.Charting.WebControl.Chart; |
|
| 24 | + if (dchart == null) |
|
| 25 | + return; |
|
| 26 | + |
|
| 27 | + foreach (Dundas.Charting.WebControl.ChartArea chartArea in dchart.ChartAreas) |
|
| 28 | + { |
|
| 29 | + chartArea.AxisY2.Enabled = Dundas.Charting.WebControl.AxisEnabled.False; |
|
| 30 | + } |
|
| 31 | + |
|
| 32 | + base.CustomizeDundasChart(chart, properties, chartType); |
|
| 33 | +} |
|
| 34 | + |
|
| 35 | + |
|
| 36 | +//Сode to use a common (left) Y axis: |
|
| 37 | +public override void CustomizeDundasChart(object chart, Hashtable properties, Type chartType) |
|
| 38 | +{ |
|
| 39 | + if (chartType.FullName != "Izenda.AdHoc.DundasBarChart") |
|
| 40 | + return; |
|
| 41 | + |
|
| 42 | + Dundas.Charting.WebControl.Chart dchart = chart as Dundas.Charting.WebControl.Chart; |
|
| 43 | + if (dchart == null) |
|
| 44 | + return; |
|
| 45 | + |
|
| 46 | + foreach (Dundas.Charting.WebControl.Series series in dchart.Series) |
|
| 47 | + { |
|
| 48 | + if (series.YAxisType == Dundas.Charting.WebControl.AxisType.Secondary) |
|
| 49 | + { |
|
| 50 | + series.YAxisType = Dundas.Charting.WebControl.AxisType.Primary; |
|
| 51 | + } |
|
| 52 | + } |
|
| 53 | + |
|
| 54 | + base.CustomizeDundasChart(chart, properties, chartType); |
|
| 27 | 55 | } |
| 56 | + |
|
| 28 | 57 | ``` |
| 29 | 58 | ### C# (HTML engine) |
| 30 | -Code to hide the right Y axis: |
|
| 59 | +//Code to hide the right Y axis: |
|
| 31 | 60 | ```csharp |
| 32 | -/* HTML charts */ |
|
| 33 | 61 | public override void CustomizeChart(object chart, Hashtable properties) |
| 34 | 62 | { |
| 35 | 63 | if (chart is StringBuilder) |
| ... | ... | @@ -40,18 +68,17 @@ public override void CustomizeChart(object chart, Hashtable properties) |
| 40 | 68 | if (!strChart.Contains("BarChart")) |
| 41 | 69 | return; |
| 42 | 70 | |
| 43 | - string pattern = @"var\s+(?BarChart\d+Instance);"; |
|
| 44 | - string chartVarName = Regex.Match(strChart, pattern).Groups[1].Value; |
|
| 71 | + string pattern = @"var\s+(?<chartvarname>BarChart\d+Instance);"; |
|
| 72 | + string chartVarName = Regex.Match(strChart, pattern).Groups["chartvarname"].Value; |
|
| 45 | 73 | |
| 46 | 74 | sb = sb.Replace("} catch (e) {", "var yAxisLength = " + chartVarName + ".yAxis.length; if(yAxisLength > 1){ for(var i = 1; i < yAxisLength; ++i){" + chartVarName + ".options.yAxis[i].labels.enabled = false; " + chartVarName + ".options.yAxis[i].title.text = null; " + chartVarName + ".yAxis[i].update();}}} catch (e) {"); |
| 47 | 75 | } |
| 48 | 76 | |
| 49 | 77 | base.CustomizeChart(chart, properties); |
| 50 | 78 | } |
| 51 | -``` |
|
| 52 | -Сode to use a common left Y axis: |
|
| 53 | -```csharp |
|
| 54 | -/* HTML charts */ |
|
| 79 | + |
|
| 80 | + |
|
| 81 | +//Сode to use a common (left) Y axis: |
|
| 55 | 82 | public override void CustomizeChart(object chart, Hashtable properties) |
| 56 | 83 | { |
| 57 | 84 | if (chart is StringBuilder) |