locked
Chart yAxis on the right and linq column as a variable. RRS feed

  • Question

  • User-352524747 posted
    @{
        var db = Database.Open((string)App.Database);
        var url = UrlData[0].ToUpper();
        if (!url.IsEmpty())
        {
            var dataquery = "SELECT [Date], {0} FROM Money WHERE [Date] > @0";
            var data = db.Query(string.Format(dataquery, url), DateTime.UtcNow.AddDays(-21));
            var minvalue = data.Select(e => new { e.url }).Min();
            var maxvalue = data.Select(e => new { e.url }).Max();
            var simplecharts = @"<Chart><ChartAreas><ChartArea _Template_=""All"" BackColor=""Transparent""><AxisY LineColor=""20, 20, 20, 20""><MajorGrid LineColor=""#f1f1f1"" /><LabelStyle Font=""Trebuchet MS"" /></AxisY><AxisX LineColor=""20, 20, 20, 20""><MajorGrid LineColor=""#f1f1f1"" /><LabelStyle Font=""Trebuchet MS"" /></AxisX></ChartArea></ChartAreas></Chart>";
            var eurallch = new Chart(width: 350, height: 200, theme: simplecharts)
            .SetYAxis(null, minvalue, maxvalue)
            .AddSeries(url, chartType: "Line", xValue: data.Select(d => d.Date.ToString("dd")).ToArray(), xField: "Date", yValues: data, yFields: url)
            .Write("png");
        }
        else
        {
            Response.Redirect("/");
        }
    }

    I have this code. I want to display the Y axis on the right of the chart, is that possible? And my second problem is that i can't use a variable as a column inside select linq, to get the min and max values.

    Monday, November 28, 2016 4:49 PM

All replies

  • User-2057865890 posted

    Hi Dow7,

    And my second problem is that i can't use a variable as a column inside select linq, to get the min and max values.

    var minvalue = (double) (from d in data select d.url).Min();
    var maxvalue = (double) (from d in data select d.url).Max();

    Best Regards,

    Chris

    Tuesday, November 29, 2016 7:52 AM
  • User-352524747 posted

    I tried it but i get System.InvalidOperationException: Invalid column name "url".

    Tuesday, November 29, 2016 9:55 AM
  • User-2057865890 posted

    Hi Dow7,

    Please change 'url' to the column name that you used in your query on the table you are trying to query from.  

    Best Regards,

    Chris

    Tuesday, November 29, 2016 11:13 AM
  • User-352524747 posted

    I want to query based on a variable. I will solve it using a switch case or a something else. What about the Y axis, is it possible to show it on the right side of the chart?

    Tuesday, November 29, 2016 12:22 PM
  • User-352524747 posted

    I will solve it using a switch case or a something else.

    i used condition ? first_expression : second_expression;

    I'm not able to find how to plot using secondary Y axis (on the right side of the chart). Is that possible?

    Friday, December 2, 2016 4:01 PM