GoogleChartsNGraphsControls.Legend

Sep 4, 2014 at 4:03 PM
When I try configure legend then I have an exception when load page:
InnerException = {"Token PropertyName in state Property would result in an invalid JSON object. Path ''."}

GoogleChartsNGraphsControls.Legend leg = new GoogleChartsNGraphsControls.Legend()
            {
                 LegendPosition = GoogleChartsNGraphsControls.LegendPostion.Default
                  
            };

GVLineChart1.GviTitle = "SOME TITLE";
GVLineChart1.GviHAxisClass = haxis;
GVLineChart1.GviVAxisClass = vaxis;
GVLineChart1.GviFontSize = 11;
GVLineChart1.GviCurveType = GoogleChartsNGraphsControls.CurveType.Function;
GVLineChart1.GviOnSelect = "OnSelect";
GVLineChart1.Width = Unit.Pixel(300);
GVLineChart1.Height = Unit.Pixel(270);
//bellow is the line that cause exception
GVLineChart1.GviLegendClass = leg;

GVLineChart1.DataSource = tbl;
Coordinator
Sep 4, 2014 at 4:38 PM
I think that I basically try to ignore anything that resolves as default. Try changing the LegendPosition. If you are going to use default then there should be no need to include anything.

Best Regards,


Julian King

Lead Software Developer

206.697.4663

[email removed]





Dec 10, 2014 at 4:03 PM
First off, Juls I want to congratulate you on creating and maintaining this wrapper. It is extremely useful and easy to use. Way to go!

Similar to @xanaducsp, I'm having problems setting options for the Legend (as well as other options such as Animation, background color, etc). I think I must be doing something wrong, but I've tried every way I can think and none of the settings seem to take. See the example below for the Legend. According to Google's API docs, setting the LegendPosition to "none" will cause no legend to be displayed. However, when I do the following it doesn't seem to have any effect. However, of interesting note when I follow the same method to set the TextStyle to a red colour text, that setting does seem to take effect on the resulting graph with the text for the legend showing in red. The text style setting takes effect, but the Legend Position values don't (I tried setting it to Bottom, Top, None, etc, all without any change in the display). Please tell me what I'm doing wrong. Thank you.
                GoogleChartsNGraphsControls.LegendPostion lp = GoogleChartsNGraphsControls.LegendPostion.None;
                GoogleChartsNGraphsControls.TextStyle ts = new GoogleChartsNGraphsControls.TextStyle();
                     ts.Color = System.Drawing.Color.Red;
                var leg = new GoogleChartsNGraphsControls.Legend(lp, ts);
                GVArea1.GviLegendClass = leg;
I've done similar for adjusting animation parameters such as duration and they also have no effect on the chart (i.e. there is no animation) (see below).
            GoogleChartsNGraphsControls.Animation anim = new GoogleChartsNGraphsControls.Animation();
                anim.Duration = 2000;  //2 second animation duration
                anim.Easing = GoogleChartsNGraphsControls.AnimationEasing.Linear;
            GVGauge1.GviAnimationClass = anim;
However, I have used similar methods with success for setting parameters for the Axes for example (see below). Why does it work for some parameters and not others?
                GoogleChartsNGraphsControls.vAxis vx = new GoogleChartsNGraphsControls.vAxis();
                    vx.MaxValue = 100;
                    vx.MinValue = 0;
                    vx.Title = "CPU %";
                    vx.Formatted = GoogleChartsNGraphsControls.AxisFormat.Percent;
                GVArea1.GviVAxisClass = vx;
                
                GoogleChartsNGraphsControls.hAxis hx = new GoogleChartsNGraphsControls.hAxis();
                    hx.Gridlines = new GoogleChartsNGraphsControls.Gridlines();
                    hx.Gridlines.Count = 7;
                GVArea1.GviHAxisClass = hx;
Thanks in advance for your help.
Coordinator
Dec 10, 2014 at 5:45 PM
Good to hear and thanks for the feedback. So all this API is really doing is building JSON and javascript. All the action happens on the page in "chart.opts". Send me the source from the page where the chart.opts is found.

For example.
chart.opts = {"is3D":true,"title":"Where I Spend My Time","legend":{position: 'left', textStyle: {color: 'blue', fontSize: 16}}};

Also, for a very fast fix that you can do yourself, pull off the JSON from the chart.opts, make any modifications and use the chart.optionsOverride = {JSON} that you want to push into the system. You can use my API to create some of the basic JSON then modify it and set it in the production chart.

Best Regards,


Julian King

Lead Software Developer

206.697.4663

[email removed]




Dec 10, 2014 at 6:18 PM
Thanks for the quick reply Juls. I think I see the issue, the JSON is being created with a typo on the word "position" under legend. I can confirm that by using the chart.optionsOverride string, with the correct spelling for position it does in fact remove the legend from the chart. Thank you for the help!

Here is the chart.opts output from the page:
chart.opts = {"title":"CPU History","titlePosition":"out","enableInteractivity":true,"focusTarget":"default","max":100,"hAxis": {"gridlines":{"count":7},"textPosition":"default","viewWindowMode":"default"},"vAxis": {"format":"#%","textPosition":"default","title":"CPU %","maxValue":1,"minValue":0,"viewWindowMode":"default"},"legend":{"postition":"none","textStyle":{"color":"Red"}}};
Craig
Coordinator
Dec 10, 2014 at 7:47 PM
Great and I will fix it in the source.

Best Regards,


Julian King

Lead Software Developer

206.697.4663

[email removed]




Coordinator
Dec 10, 2014 at 7:48 PM
Oh. And animations seem to work on redraws of the data, but the initial drawing does not appear to render with the animations. I don't know what the cause is of that.

Best Regards,


Julian King

Lead Software Developer

206.697.4663

[email removed]