Tuesday, February 25, 2014

NextCharts: Combo Bar Line Charts

NextCharts supports bar and stacked bar combo charts. This means there can be more series inside a chart some bars / stacked bars, some lines.

A simple stacked bar json like:
{
   "type":"stackedbar",
   "style":"glass", 
   "data":[[16,66,24,30,80,52],[48,50,29,60,60,58],[30,40,28,52,34,50]],  
   "labels":["JAN","FEB","MAR","APR","MAY","JUN"], 
   "color":["#004CB3","#A04CB3","#7aa37a"],
   "legend":["2011","2012","2013"],
   "alpha":0.6, 
   "showGridX":true, 
   "showGridY":true, 
   "colorGridX":"rgb(0,198,189)", 
   "colorGridY":"rgb(0,198,189)", 
   "message":"Value #val from #total", 
   "tickCount":4,
   "title":{
        "text":"Financial Analysis",
        "font":{"weight":"bold", "size":16, "family":"sans-serif"},
        "color":"blue",
        "alignment":"center"
   },        
   "xData":{
        "font":{"weight":"bold", "size":14,"family":"sans-serif"},
        "color":"blue"
   },                          
   "yData":{
        "font":{"weight":"bold","size":14,"family":"sans-serif"},
        "color":"blue"
   },
   "xLegend":{
        "text":"Month",
        "font":{"weight":"bold","size":14,"family":"sans-serif"},
        "color":"#993366"
   },"
   "yLegend":{
        "text":"Price",
        "font":{"weight":"bold","size":14,"family":"sans-serif"},
        "color":"#993366"
   }
}
will look like:

To add combo lines (2 lines in this example)  we should add some properties to json object:
{
...
 "lineData":[[31.33, 52, 27, 47.33, 74.66, 53.33],[100, 120, 53, 190, 40, 130]],
 "lineColor":["#270283", "#CC6633"],
 "lineLegend":["Average", "Profit"],
...
}
With these, we obtain a combo chart like:


Friday, February 21, 2014

NextCharts: Styles

Styles are different ways to show a specific kind of charts. These are different for bar and line charts.
For bars these can be normal, glass, cylinder, parallelepiped and dome. For lines these can be  normal, soliddot, hollowdot, anchordot, bowdot, stardot.

Lets take a simple horizontal stacked bar chart:

1. normal
2. glass
3. cylinder
4. parallelepiped
5. dome

A simple line chart:

1. normal
2. soliddot
3. hollowdot
4. anchordot
5. bowdot
6. stardot

Thursday, February 20, 2014

NextCharts: A Developer Perspective

NextCharts is "the new kid in town" for NextReports Suite. It is a simple and nice HTML5 library,  created with Javascript and JQuery, which can be used by developers to show different types of charts.

Charts are drawn on a HTML5 canvas and tooltips are shown on a different canvas. Chart is passed as a JSON object. You can call the chart drawing function using as parameters the json and the ids of the two canvases:
nextChart(json, idCanvas, idTooltipCanvas)
In this case the chart will have the size of the canvas as specified inside CSS/HTML.

You can also specify the width and height in pixels or as percents:
nextChart(json, idCanvas, idTooltipCanvas, canvasWidth, canvasHeight)
A simple HTML page that shows a NextChart can specify (through css) how the tooltip will look. In this example there is a url that serves a json:
<html>
<head>

<title>NextReports Chart</title>

<style type="text/css">
  .tip {
    background-color:white;
    border:1px solid gray;
    border-radius: 5px;
    -moz-border-radius: 5px;
    -webkit-border-radius: 5px;
    position:absolute;
    left:-200px;
    top:100px;
  }
  
  .canvas {
   border: 1px solid gray;
  }
</style>

<script src="js/jquery-1.10.2.min.js" type="text/javascript"></script>
<script src="js/nextcharts-1.0.min.js" type="text/javascript"></script>
<script>

 $.ajax({
     type: "POST",
     url: "data-html5.json",
     contentType: "application/json; charset=utf-8",
     dataType: "json",    
     success: function(data) {
         console.log(data);
         nextChart(data, 'canvas', 'tip');
     },
     error: function(jqXHR, textStatus, errorThrown) {
         alert("Error: " + textStatus + " errorThrown: " + errorThrown);
     }
});     
</script>
</head>

<body>
    <canvas class="canvas" id="canvas" width="500" height="300"></canvas>
    <canvas class="tip" id="tip" width="1" height="25"></canvas>
</body>

</html>

Following we are taking about Json object structure. As a minimal set of characteristics, only the data and type properties are needed.
{
   "type":"bar",
   "data":[[16,66,24,30,80,52],[48,50,29,60,70,58],[30,40,28,52,74,50]],    
}
This will generate a bar series chart:

Type property can take a value from:  bar, stackedbar, hbar, hstackedbar, line, area, pie.

If you do not specify even type, then by default line is used.

Lets add some labels and change the colors:
{
   "type":"bar",
   "data":[[16,66,24,30,80,52],[48,50,29,60,70,58],[30,40,28,52,74,50]],
   "labels":["JANUARY","FEBRUARY","MARCH","APRIL","MAY","JUNE"],
   "color":["#004CB3","#A04CB3","#7aa37a"]
}
Lets change the style and add some alpha to colors:
{
   "type":"bar",
   "data":[[16,66,24,30,80,52],[48,50,29,60,70,58],[30,40,28,52,74,50]],
   "labels":["JANUARY","FEBRUARY","MARCH","APRIL","MAY","JUNE"],
   "color":["#004CB3","#A04CB3","#7aa37a"],
   "style":"glass",
   "alpha":0.6
}
Style property can have different values for different chart types. For bar charts it can be one of the following: normal, glass, cylinder, dome, parallelepiped. For line charts it can be: normal, soliddot, hollowdot, anchordot, bowdot, stardot.

Lets hide the grid and add a legend:
{
   "type":"bar",
   "data":[[16,66,24,30,80,52],[48,50,29,60,70,58],[30,40,28,52,74,50]],
   "labels":["JANUARY","FEBRUARY","MARCH","APRIL","MAY","JUNE"],
   "color":["#004CB3","#A04CB3","#7aa37a"],
   "style":"glass",
   "alpha":0.6,
   "showGridX":false, 
   "showGridY":false,
   "legend":["2011 First year of work","2012 Second year of work","2013 Third year of work"]
}

Lets change labels fonts and colors and show a title:
{
   "type":"bar",
   "data":[[16,66,24,30,80,52],[48,50,29,60,70,58],[30,40,28,52,74,50]],
   "labels":["JANUARY","FEBRUARY","MARCH","APRIL","MAY","JUNE"],
   "color":["#004CB3","#A04CB3","#7aa37a"],
   "style":"glass",
   "alpha":0.6,
   "showGridX":false, 
   "showGridY":false,
   "legend":["2011 First year of work","2012 Second year of work","2013 Third year of work"],
   "title":{
         "text":"Financial Analysis", 
         "font":{
              "weight":"bold", 
              "size":16, 
              "family":"sans-serif"
         }, 
         "color":"blue"
   },
   "xData":{
           "font":{
              "weight":"bold",
              "size":10,
              "family":"sans-serif"
           }, 
           "color":"blue"
   },
   "yData":{
           "font":{
              "weight":"bold",
              "size":10,
              "family":"sans-serif"
           }, 
           "color":"blue"
   }          
}

There are also other properties like:

tickCount: how many ticks are shown on y axis
message: message format for tooltip
tooltipPattern: a pattern for tooltip
background: background color
labelOrientation: x label orientation (horizontal, vertical, diagonal, halfdiagonal)
onClick: javascript function for click events

Friday, February 14, 2014

NextCharts: a new HTML5 library for NextReports

NextReports will reach a new version soon. A new year, a new major version. When I see 7.0 I have to say I am overwhelmed that NextReports starts its seven year. Looking behind, every release brought something new to make NextReports a tool for everyone. Evolution was not a process to push features just to have them (because others have), but a smooth and natural process to help our users needs.

NextReports 7.0 will bring a new chart library called NextCharts. It is a simple HTML5 library created to fulfill the needs of our open source product. Before it, NextReports used a flash library called OpenFlashCharts. It was a very good free library which served well our purposes. But because flash support is loosing  ground in recent software development, it was time for us to build from scratch a new HTML5 library which also allows for other OS smooth integration like Android systems. It became cumbersome to scratch your head on how to add flash plugin on some Android devices.

NextCharts will support all the features NextReports used in chart layout, no compromises were made. Starting from here, it will also allow us to grow the number of chart types. For version 7.0 you can have horizontal stacked bars, bar-line combos and stacked bar-line combos. Also stacked bars can have now any style as simple bars: normal, glass, cylinder, parallelepiped, dome.


Old flash support was not yet removed, because there are some places where technology is slowly introduced and modern browsers with HTML5 support are not available. That's why if your "dinosaur" browser does not understand HTML5, on NextReports Server you will automatically see a flash chart. (you need to have the flash plugin). That's why in designer you will have both HTML5 and flash previews.

NextCharts will fit as a glove for NextReports Server. From user perspective nothing is changed. Anyway, following is a glimpse on how the new charts look:


Choosing right colors makes the difference. Having just a black background for charts will create something quite different:


When user creates the chart in designer, he can choose to preview as HTML5, flash or image. If browser version is not a problem, users can forget about flash. Newer chart types do not have a correspondence to flash, so if you are stick with flash, you are stick with the old set of chart types.


Stay tuned! NextReports 7.0 is coming soon!