Today I'm going to tell you a more interesting thing that I've met in one of my recent projects.
First of all, the need for this project is to provide a graph of information integration analysis in the front-end display interface, where we have chosen to use column charts.
Take an example of how many people are in every village in a town:
First of all to determine the y-axis data interval is how much, we set here for 20px;
Because the front-end browser height tag to get the corresponding data when the use of rounding, but here in the display is obviously not enough for the integer value;
If we set the y-axis about every 20px spacing is 100 population, then if it is 99 people, the actual column chart height should be 99/100*20=19.8px;
However, height only take the integer value is 19px, so that there will be a lot of errors, so that the completion of the system and credibility greatly reduced;
Of course, there are a lot of people here who will think of why not use percentages, yes I thought of the percentage, but when you actually use it, you will find that the height tag will only take the whole number when using a percentage;
For example, we need a value of 19.8%, then height will only take 19%, so when the amount of information is very large error will be greater;
So, both of these methods are not possible, so I'm here to provide you with a feasible method:
We use the PX and EM conversion methods, 1EM=16PX, but I don't know if it's my browser or other reasons, and when I use this value, the information I'm using is not what I want,
How to use this, we still set the number of 99 people, then in the calculation is the case: 99/100*20/16 This value is the value we convert to EM, in the page code in the height of the px into EM;
So you can check the interface code to see that the height of the column chart at this time is 19.8px; my browser is using Google Chrome, and when I convert it I find that the result of using the 16来 conversion is not what I want, I then calculated that the value I got was 13.989899, so I used that value in the conversion.
But in the actual process of doing the project, we are asking this column chart can be changed with the integration of database information, so as to better improve the system's integrity, the following is to give you an example:
We are using the. NET language programming here
Controller section:
Public ActionResult Showhumanofvillage () {
Numberofpersonmodel model=new Numberofpersonmodel ();
Model. fengxiangcun=99;
Model. Fengxiangcun=model. fengxiangcun/100*20/13.989899;
return View (model);
}
View section:
@model Numberofpersonmodel
@{
String ems= "em";
}
Here to give you a reminder, and then to set the value of the height, after the value of a direct add em, or add a space after adding em is wrong
For example: <canvas class= "Jqplot-series-shadowcanvas" style= "Position:absolute; left:90px; Bottom:20px;border-color:rgba (246, 156, 147, 0.8); height: @Model. fengxiangcunem; width:50px; " ></canvas>
or <canvas class= "Jqplot-series-shadowcanvas" style= "Position:absolute; left:90px; Bottom:20px;border-color:rgba (246, 156, 147, 0.8); height: @Model. Fengxiangcun em; width:50px; " ></canvas>
So we take the form of string concatenation
<canvas class= "Jqplot-series-shadowcanvas" style= "Position:absolute; left:90px; Bottom:20px;border-color:rgba (246, 156, 147, 0.8); height: @Model. fengxiangcun.tostring () @ems; width:50px; " ></canvas>
So we'll find that the value shown in the final height here is 19.8px, exactly what we want.
This method is I in this project development process encountered this kind of problem through thinking and practice and do a feasible way, I hope you in the process of production projects encountered this kind of problem can be solved faster.
At the same time, I hope more and more experienced seniors can give more advice, so that students can learn more useful knowledge for students 1 years after the job to add more experience and strength, grateful!!!!!
How you can set the value in the Height tab to be a floating-point number