Home Forums Chart Support Multiseries Line Chart Mixture on Draw Reply To: Multiseries Line Chart Mixture on Draw

#38815

There’s another question I have during chart creation. I am building my chart.options.data in the backend since the client can select x number of different data types and a time range. So, I use the code piece below to populate the CanvasJS chart data.

string jsCanvasData = string.Empty;
                foreach (var packetsInName in chart_data_list.GroupBy(x => x.data_name))
                {
                    List<DataPoint> dataPoints2 = new List<DataPoint>();
                    packetsInName.ToList().ForEach(a => dataPoints2.Add(
                        new DataPoint(
                        ((DateTimeOffset)a.inserted_date_time).ToUnixTimeSeconds() * 1000
                        , a.data_value)));

                    //A buffer to the end of the chart to see it better
                    dataPoints2.Add(new DataPoint(((DateTimeOffset)end_data_date_time.AddHours(2)).ToUnixTimeSeconds() * 1000, null));
                    jsCanvasData += "{type: \"line\",\r\n" +
                    "highlightEnabled: true," +
                    "markerType:\"circle\"," +
                    "xValueType:\"dateTime\"," +
                    "xValueFormatString:\"DD MMMMM YYYY HH:mm:ss\"," +
                    "name:'" + packetsInName.Key + "'," +
                    "showInLegend: true," +
                    "dataPoints:" + JsonConvert.SerializeObject(dataPoints2) + "},";
                }

Is there a better way you could suggest?