Home
Options

how to plot multiple lines in same chart or plot the chart with 2 graphs side by side

i would like to plot two indicator lines on same chart or show the charts side by side. the current example i put here shows 2 charts in 2 different tabs. how can i fix it?

void Main()
{



    string json1 = "[\r\n  {\r\n    \"entryTime\": \"2019-01-08T00:00:01\",\r\n    \"gains\": -0.00071,\r\n    \"cumulativegains\": -0.00071\r\n  },\r\n  {\r\n    \"entryTime\": \"2019-01-08T05:00:01\",\r\n    \"gains\": -0.00102,\r\n    \"cumulativegains\": -0.00102\r\n  },\r\n  {\r\n    \"entryTime\": \"2019-01-08T09:00:01\",\r\n    \"gains\": -0.00113,\r\n    \"cumulativegains\": -0.00113\r\n  },\r\n  {\r\n    \"entryTime\": \"2019-01-08T10:31:19\",\r\n    \"gains\": -0.00236,\r\n    \"cumulativegains\": -0.00236\r\n  },\r\n  {\r\n    \"entryTime\": \"2019-01-09T20:21:34\",\r\n    \"gains\": -0.00262,\r\n    \"cumulativegains\": -0.00262\r\n  },\r\n  {\r\n    \"entryTime\": \"2019-01-11T16:00:01\",\r\n    \"gains\": -0.00075,\r\n    \"cumulativegains\": -0.00075\r\n  },\r\n ]";

    string json2="[\r\n  {\r\n    \"entryTime\": \"2019-01-02T05:00:01\",\r\n    \"gains\": 0.00591,\r\n    \"cumulativegains\": 0.00591\r\n  },\r\n  {\r\n    \"entryTime\": \"2019-01-03T10:00:01\",\r\n    \"gains\": 0.00139,\r\n    \"cumulativegains\": 0.00139\r\n  },\r\n  {\r\n    \"entryTime\": \"2019-01-04T08:30:02\",\r\n    \"gains\": -0.00434,\r\n    \"cumulativegains\": -0.00434\r\n  },\r\n  {\r\n    \"entryTime\": \"2019-01-07T23:00:01\",\r\n    \"gains\": -0.00172,\r\n    \"cumulativegains\": -0.00172\r\n  },\r\n  {\r\n    \"entryTime\": \"2019-01-08T05:00:01\",\r\n    \"gains\": -0.00096,\r\n    \"cumulativegains\": -0.00096\r\n  },\r\n  {\r\n    \"entryTime\": \"2019-01-08T08:00:01\",\r\n    \"gains\": -0.00048,\r\n    \"cumulativegains\": -0.00048\r\n  },\r\n  {\r\n    \"entryTime\": \"2019-01-08T14:00:01\",\r\n    \"gains\": -0.00037,\r\n    \"cumulativegains\": -0.00037\r\n  },\r\n  {\r\n    \"entryTime\": \"2019-01-09T09:00:01\",\r\n    \"gains\": -0.00169,\r\n    \"cumulativegains\": -0.00169\r\n  }\r\n]";

    List<trades2plot> jsonData1 = JsonConvert.DeserializeObject<List<trades2plot>>(json1);
    List<trades2plot> jsonData2 = JsonConvert.DeserializeObject<List<trades2plot>>(json2);


    jsonData1.Chart(c => c.entryTime, c => c.cumulativegains, Util.SeriesType.Line).Dump();
    jsonData2.Chart(c => c.entryTime, c => c.cumulativegains, Util.SeriesType.Line).Dump();

}
public class trades2plot
{

    public DateTime entryTime;

    public double gains;
    public double cumulativegains;
    public trades2plot() { }
}


// You can define other methods, fields, classes and namespaces here

Comments

  • Options

    To display two charts side-by-side, use Util.HorizontalRun:

    var chart1 =jsonData1.Chart (c => c.entryTime, c => c.cumulativegains, Util.SeriesType.Line);
    var chart2 = jsonData2.Chart (c => c.entryTime, c => c.cumulativegains, Util.SeriesType.Line);
    
    Util.HorizontalRun (true, chart1.ToBitmap(700, 500), chart2.ToBitmap(700, 500)).Dump();
    
    

    To join the charts together, you will need to do a union. Something like this:

    var union = 
        jsonData1.Select (d => new { d.entryTime, Series1 = (double?) d.cumulativegains, Series2 = (double?) null })
        .Union (
        jsonData2.Select (d => new { d.entryTime, Series1 = (double?) null, Series2 = (double?) d.cumulativegains }));
    
    union
        .Chart (c => c.entryTime, c => c.Series1, Util.SeriesType.Line)
        .AddYSeries (c => c.Series2, LINQPad.Util.SeriesType.Line)
        .Dump();
    
  • Options

    wow. i understand the first example. the second example is bit too complex for me. is there any reference material that i can read to understand it better

  • Options

    The union is just to get the series onto the same x-axis. You can see what it's doing by dumping the union variable.

Sign In or Register to comment.