how to enable time series data in flot chart? - time-series

Flot documentation says that it is based on javascript timestamp.
I have tried to convert my JSON to comply this standard, and my JSON looks like this
{"label":"Activation","data": [
["1382061194000","10"],["1382061195000","9"],["1382061196000","9"],
["1382061197000","20"],["1382061198000","6"],["1382061203000","16"],
["1382061204000","12"],["1382061205000","14"],["1382061206000","22"],
["1382061207000","20"],["1382061208000","10"],["1382061209000","19"],
["1382061210000","13"],["1382061211000","9"],["1382061212000","12"],
["1382061214000","12"],["1382061215000","17"],["1382061216000","6"],
["1382061217000","14"],["1382061218000","22"],["1382061219000","43"],
["1382061220000","34"],["1382061221000","27"],["1382061222000","31"],
["1382061223000","2"],["1382061224000","1"],["1382061225000","86"],
["1382061226000","82"],["1382061227000","4"],["1382061228000","7"],
["1382061229000","6"],["1382061230000","18"],["1382061231000","17"],
["1382061232000","15"],["1382061233000","3"],["1382061234000","14"],
["1382061235000","2"],["1382061236000","8"],["1382061237000","14"],
["1382061238000","9"],["1382061239000","5"]
]}
And i setup flot options like this
xaxis: {tickSize: 1,mode: "time", timeformat: "%H:%M:%S"}
The chart never up :(
Well actually the goal is simple, I just want to show a flot chart with 08:02:30 08:02:31 as the xaxis info. Thanks for any help.

Your problem is that you're passing in your dates as strings.
> new Date("1382061194000")
Invalid Date
> new Date(1382061194000)
Thu Oct 17 2013 21:53:14 GMT-0400 (EDT)
Try removing the quotes (around your data points too) and see what that does.

Related

Highcharts json data date in zulu time not working

I was trying to follow this demo https://jsfiddle.net/gh/get/library/pure/highcharts/highcharts/tree/master/samples/highcharts/data/livedata-rows
But can not understand why the date/time is not showing up correctly for me I have it in the exact same format and only changed the link in this example to a local host where I am serving my json file this is what my json looks like
{
"vtg": [
["2021-06-18T16:46:38.981Z", 7.131307519877803],
["2021-06-18T16:46:39.981Z", 6.728442167327733],
["2021-06-18T16:46:40.981Z", 1.272020585570508],
["2021-06-18T16:46:41.981Z", 6.80643850015173],
["2021-06-18T16:46:42.981Z", 3.493474821467808],
["2021-06-18T16:46:43.981Z", 2.1728923419279234],
["2021-06-18T16:46:44.981Z", 8.33079253512965],
["2021-06-18T16:46:45.981Z", 6.068523773578017],
["2021-06-18T16:46:46.981Z", 5.704502768230142],
["2021-06-18T16:46:47.981Z", 1.6336430526049028]
],}
In the example it has the time on the bottom axis and when you hover it gives the full date and time but when I try it with mine the bottom axis becomes 0-10 and the tool-tip shows the exact string. To check I even followed the link in the example that it was pulling data from to make sure the time was formatted correctly but I cant seem to find what I did wrong.
In the documentation you can find that the data should be structured as a row array:
A URL to a remote JSON dataset, structured as a row array. Will be fetched when the chart is created using Ajax.
API: https://api.highcharts.com/highcharts/data.rowsURL
Meanwhile, your data structure is an object: https://jsfiddle.net/BlackLabel/80btkhgx/
series: [{
data: data['vtg']
}]

Highcharts version 8.2.0 tilemap doesn't support "square" shape

I've been using highcharts 7.2.0 tilemap chart, but after updating to version 8.2.0, I'm getting an error when tileShape is set to "square"
In my https://jsfiddle.net/nqxm2yk7/1/ , tileShape is set to 'circle', but if you change it to "square", it will be crash.
Although the official documentation says, that we can use four different types of shapes
Is anyone has the same problem?
[1]: https://jsfiddle.net/nqxm2yk7/1/
If you want square tiles you will need to set the chart type to "heatmap":
chart: {
type: 'heatmap',
height: '120%'
},
and also include heatmap.js
Fiddle
I found that it is a regression and I reported it on the Highcharts Github issue channel where you can follow this thread: https://github.com/highcharts/highcharts/issues/14267. If you need a temporary workaround please ask in the comment for it - the core developers will take care of your case.

How to include plugins when exporting my chart?

How do I include plugins for use with the highcharts-export-server? I am trying to use the highcharts-regression plugin.
I tried to use the -resources option to specify the plugin's JS file (both as a local file and as a full URL) file but no regression lines are added to my charts, unlike my browser based version which has the regression lines added.
My command is:
highcharts-export-server
-resources: {"files":"https://github.com/streamlinesocial/highcharts-regression/blob/master/highcharts-regression.js"}
-instr '{"chart":{"type":"line"},"title":{"text":"Total Downtime"},"xAxis":{"type":"datetime","dateTimeLabelFormats":{ day: "%b %Y"}},"yAxis":{"allowDecimals":false,"min":0,"tickInterval":1,"title":{"text":"Percentage"}},"series":[{"name":"BOILER 04/WATERWALL","color":"#2f7ed8","regression":true,"regressionSettings":{"name":"BOILER 04/WATERWALL trend","type":"linear","dashStyle":"dash","color":"#2f7ed8"},"data":[{"x":1451599200000,"y":0,"viewType":"M"},{"x":1454277600000,"y":0,"viewType":"M"},{"x":1456783200000,"y":0,"viewType":"M"},{"x":1459461600000,"y":0,"viewType":"M"},{"x":1462053600000,"y":0,"viewType":"M"},{"x":1464732000000,"y":4.97,"viewType":"M"},{"x":1467324000000,"y":4.89,"viewType":"M"},{"x":1470002400000,"y":0,"viewType":"M"},{"x":1472680800000,"y":0,"viewType":"M"},{"x":1475272800000,"y":0,"viewType":"M"},{"x":1477951200000,"y":0,"viewType":"M"},{"x":1480543200000,"y":0,"viewType":"M"},{"x":1483221600000,"y":0,"viewType":"M"},{"x":1485900000000,"y":0,"viewType":"M"},{"x":1488319200000,"y":0,"viewType":"M"},{"x":1490997600000,"y":0,"viewType":"M"},{"x":1493589600000,"y":0,"viewType":"M"},{"x":1496268000000,"y":0,"viewType":"M"},{"x":1498860000000,"y":0,"viewType":"M"}]}]}'
-outfile sample.png
The chart is generated fine but without the regression plugin features added. The same sort of code works fine when generating the chart in the browser, not using the export-server. Thanks!
This works with a few minor "type-o" fixes. Given the above command you've provided, I've changed -resources: {...} to --resources '{...}', as well as -instr to --instr and -outfile to --outfile, as per the documentation. Although, I think only the colon as well as the quoting are the relevant changes:
highcharts-export-server
--resources '{"files":"highcharts-regression.js"}'
--instr '{"chart":{"type":"line"},"title":{"text":"Total Downtime"},"xAxis":{"type":"datetime","dateTimeLabelFormats":{ day: "%b %Y"}},"yAxis":{"allowDecimals":false,"min":0,"tickInterval":1,"title":{"text":"Percentage"}},"series":[{"name":"BOILER 04/WATERWALL","color":"#2f7ed8","regression":true,"regressionSettings":{"name":"BOILER 04/WATERWALL trend","type":"linear","dashStyle":"dash","color":"#2f7ed8"},"data":[{"x":1451599200000,"y":0,"viewType":"M"},{"x":1454277600000,"y":0,"viewType":"M"},{"x":1456783200000,"y":0,"viewType":"M"},{"x":1459461600000,"y":0,"viewType":"M"},{"x":1462053600000,"y":0,"viewType":"M"},{"x":1464732000000,"y":4.97,"viewType":"M"},{"x":1467324000000,"y":4.89,"viewType":"M"},{"x":1470002400000,"y":0,"viewType":"M"},{"x":1472680800000,"y":0,"viewType":"M"},{"x":1475272800000,"y":0,"viewType":"M"},{"x":1477951200000,"y":0,"viewType":"M"},{"x":1480543200000,"y":0,"viewType":"M"},{"x":1483221600000,"y":0,"viewType":"M"},{"x":1485900000000,"y":0,"viewType":"M"},{"x":1488319200000,"y":0,"viewType":"M"},{"x":1490997600000,"y":0,"viewType":"M"},{"x":1493589600000,"y":0,"viewType":"M"},{"x":1496268000000,"y":0,"viewType":"M"},{"x":1498860000000,"y":0,"viewType":"M"}]}]}'
--outfile sample.png
This successfully gives me the following result with Highcharts export server 2.0.24:
Also, if attempting to use an URL you should probably point to the raw file, but I didn't have any success doing so, so I used a local version of the highcharts-regression.js file.

Can highcharts export POST a JSON options object instead of SVG?

I'm using highcharts-convert.js with phantomjs, and I'm having some text-overlapping issues when exporting the charts.
I believe the reason is Chrome on OSX renders fonts differently than my ubuntu server does. So when the client's browser builds the SVG the text does not overlap (I have indeed confirmed this by capturing the POST and rendering the svg in Chrome), but when phantomjs renders the text on ubuntu its slightly wider so there is overlap.
I believe that if I export the options JSON rather than SVG, ubuntu will lay out the text according to its own font rendering, and nothing will overlap.
Does that make sense? If so, how can I get highcharts to POST the options JSON rather than SVG?
I have this process that I can use to rig everything up, but it feels like there should be a better way...
var chart = graphContainer.find(".graph-body div").highcharts();
var chartOptions = chart.options;
delete chartOptions.chart["renderTo"]; // this creates a circular reference
// provide extra options to override the chart's defaults here...
$.extend(chartOptions.chart, {backgroundColor: "#FFFFFF", spacingLeft: 30, spacingRight: 30});
// wrap this up and POST it to the server...
console.log(JSON.stringify(chartOptions));

JqGrid DataBinding exception while exporting to excel file

I am trying to export JqGrid to excel so i follow this instruction and i use it like at below.
var grid = new JqGridModelParticipiant().JqGridParticipiant;
var query = db.ReservationSet.Select(r => new
{
r.Id,
Name = r.Doctor.Name,
Identity = r.Doctor.Identity,
Title = r.Doctor.Title.Name,
Total = r.TotalTL,
Organization = r.Organization.Name
});
grid.ExportToExcel(query,"file.xls");
And i get below exception on the line of " grid.ExportToExcel(query,"file.xls");"
Data binding directly to a store query (DbSet, DbQuery, DbSqlQuery) is
not supported. Instead populate a DbSet with data, for example by
calling Load on the DbSet, and then bind to local data. For WPF bind
to DbSet.Local. For WinForms bind to DbSet.Local.ToBindingList().
As far as i understand that it expect to have ObservableCollection that is on DbSet.Local member. But i am working on projected query so i can't do that.
What is the solution for this problem.
In the answer I posted the demo which shows how to implement export to Excel (real *.XLSX file instead of HTML fragment renamed to *.XLS used here).
The method used for exported to the Excel in jqSuite (the demo) produce HTML fragment like
HTTP/1.1 200 OK
Cache-Control: private
Content-Type: application/excel; charset=utf-8
Server: Microsoft-IIS/7.0
X-AspNetMvc-Version: 2.0
content-disposition: attachment; filename=grid.xls
X-AspNet-Version: 2.0.50727
X-Powered-By: ASP.NET
Date: Fri, 29 Jun 2012 14:24:54 GMT
Connection: close
<table cellspacing="0" rules="all" border="1" id="_exportGrid" style="border-collapse:collapse;">
<tr>
<td>OrderID</td><td>CustomerID</td><td>OrderDate</td><td>Freight</td><td>ShipName</td>
</tr><tr>
<td>10248</td><td>VINET</td><td>1996/07/04</td><td>32.3800</td><td>Vins et alcools Chevalier</td>
</tr><tr>
<td>10249</td><td>TOMSP</td><td>1996/07/05</td><td>11.6100</td><td>Toms Spezialitäten</td>
</tr><tr>
<td>10250</td><td>HANAR</td><td>1996/07/08</td><td>65.8300</td><td>Hanari Carnes</td>
</tr><tr>
...
</table>
instead of creating of real Excel file. The way is very unsafe because at the opening the "Standard" type of data will be always used. For example if you would export the data like
<td>10249</td><td>TOMSP</td><td>1996/07/05</td><td>11.02.12</td><td>Toms Spezialitäten</td>
the text "11.02.12" will be automatically converted to the date 11.02.2012 if German locale are used as default:
The name "Toms Spezialitäten" from will be wrong displayed as "Toms Spezialitäten".
It can be especially dangerous in case of large table where some small part of data in the middle of grid will be wrong converted. In one project I displayed information about Software and some software versions will be wrong converted to the Date type.
Because of such and other close problems I create real Excel file on the server using Open XML SDK 2.5 or Open XML SDK 2.0. In the way one have no problems described above. So I recommend you to follow the approach described in my old answer.

Resources