834d85fde02b0d603964e2a055bca0aaceafaf1c
FAQ/How-do-I-set-only-one-Y-axis-in-a-chart.md
| ... | ... | @@ -11,6 +11,49 @@ Izenda charts will display two or more y axes on a chart if multiple plotted ite |
| 11 | 11 | |
| 12 | 12 | |
| 13 | 13 | If you would like to override this feature and display only one chart, you can use the following code: |
| 14 | +### C# (HTML engine) |
|
| 15 | + |
|
| 16 | +```csharp |
|
| 17 | +//Code to hide the right Y axis: |
|
| 18 | +public override void CustomizeChart(object chart, Hashtable properties) |
|
| 19 | +{ |
|
| 20 | + if (chart is StringBuilder) |
|
| 21 | + { |
|
| 22 | + StringBuilder sb = (StringBuilder)chart; |
|
| 23 | + String strChart = sb.ToString(); |
|
| 24 | + |
|
| 25 | + if (!strChart.Contains("BarChart")) |
|
| 26 | + return; |
|
| 27 | + |
|
| 28 | + string pattern = @"var\s+(?<chartvarname>BarChart\d+Instance);"; |
|
| 29 | + string chartVarName = Regex.Match(strChart, pattern).Groups["chartvarname"].Value; |
|
| 30 | + |
|
| 31 | + 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) {"); |
|
| 32 | + } |
|
| 33 | + |
|
| 34 | + base.CustomizeChart(chart, properties); |
|
| 35 | +} |
|
| 36 | + |
|
| 37 | + |
|
| 38 | +//Сode to use a common (left) Y axis: |
|
| 39 | +public override void CustomizeChart(object chart, Hashtable properties) |
|
| 40 | +{ |
|
| 41 | + if (chart is StringBuilder) |
|
| 42 | + { |
|
| 43 | + StringBuilder sb = (StringBuilder)chart; |
|
| 44 | + String strChart = sb.ToString(); |
|
| 45 | + |
|
| 46 | + if (!strChart.Contains("BarChart")) |
|
| 47 | + return; |
|
| 48 | + |
|
| 49 | + sb = sb.Replace("yAxis: 1", ""); |
|
| 50 | + } |
|
| 51 | + |
|
| 52 | + base.CustomizeChart(chart, properties); |
|
| 53 | +} |
|
| 54 | + |
|
| 55 | +``` |
|
| 56 | + |
|
| 14 | 57 | |
| 15 | 58 | ### C# (Dundas engine) |
| 16 | 59 | ```csharp |
| ... | ... | @@ -55,47 +98,7 @@ public override void CustomizeDundasChart(object chart, Hashtable properties, Ty |
| 55 | 98 | } |
| 56 | 99 | |
| 57 | 100 | ``` |
| 58 | -### C# (HTML engine) |
|
| 59 | -//Code to hide the right Y axis: |
|
| 60 | -```csharp |
|
| 61 | -public override void CustomizeChart(object chart, Hashtable properties) |
|
| 62 | -{ |
|
| 63 | - if (chart is StringBuilder) |
|
| 64 | - { |
|
| 65 | - StringBuilder sb = (StringBuilder)chart; |
|
| 66 | - String strChart = sb.ToString(); |
|
| 67 | 101 | |
| 68 | - if (!strChart.Contains("BarChart")) |
|
| 69 | - return; |
|
| 70 | - |
|
| 71 | - string pattern = @"var\s+(?<chartvarname>BarChart\d+Instance);"; |
|
| 72 | - string chartVarName = Regex.Match(strChart, pattern).Groups["chartvarname"].Value; |
|
| 73 | - |
|
| 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) {"); |
|
| 75 | - } |
|
| 76 | - |
|
| 77 | - base.CustomizeChart(chart, properties); |
|
| 78 | -} |
|
| 79 | - |
|
| 80 | - |
|
| 81 | -//Сode to use a common (left) Y axis: |
|
| 82 | -public override void CustomizeChart(object chart, Hashtable properties) |
|
| 83 | -{ |
|
| 84 | - if (chart is StringBuilder) |
|
| 85 | - { |
|
| 86 | - StringBuilder sb = (StringBuilder)chart; |
|
| 87 | - String strChart = sb.ToString(); |
|
| 88 | - |
|
| 89 | - if (!strChart.Contains("BarChart")) |
|
| 90 | - return; |
|
| 91 | - |
|
| 92 | - sb = sb.Replace("yAxis: 1", ""); |
|
| 93 | - } |
|
| 94 | - |
|
| 95 | - base.CustomizeChart(chart, properties); |
|
| 96 | -} |
|
| 97 | - |
|
| 98 | -``` |
|
| 99 | 102 | |
| 100 | 103 | |
| 101 | 104 | ###VB (Dundas Engine) |