How to bind database in Syncfusion Bar Chart on Asp.net mvc - asp.net-mvc

I tried to use the code on its documentation but it's still not running even if it's static data. Here is the code on the link that I've used but it is not connected to the database. Here are the pictures of the codes I've used:
//CS File(I JUST PUT HERE)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Syncfusion.EJ2.Charts;
namespace EJ2MVCSampleBrowser.Controllers.Chart
{
public partial class ChartController : Controller
{
// GET: RoundedColumn
public ActionResult RoundedColumn()
{
List<RoundedColumnChartData> chartData = new List<RoundedColumnChartData>
{
new RoundedColumnChartData { x= "BGD", y= 106, text= "Bangaladesh" },
new RoundedColumnChartData { x= "BTN", y= 103, text= "Bhutn" },
new RoundedColumnChartData { x= "NPL", y= 198, text= "Nepal" },
new RoundedColumnChartData { x= "THA", y= 189, text= "Thiland" },
new RoundedColumnChartData { x= "MYS", y= 250, text= "Malaysia" }
};
ViewBag.dataSource = chartData;
ViewBag.font = new { fontWeight = "600", color = "#ffffff" };
return View();
}
public class RoundedColumnChartData
{
public string x;
public double y;
public string text;
}
}
}
//CSHTML File (I JUST PUT HERE)
<script src="~/Scripts/theme-color.js"></script>
<div class="control-section">
<div style="text-align:center">
#Html.EJS().Chart("container").Series(series =>
{
series.Type(Syncfusion.EJ2.Charts.ChartSeriesType.Column).XName("x").YName("y")
.CornerRadius(cr=>cr.BottomLeft(10).BottomRight(10).TopLeft(10).TopRight(10))
.Marker(mr => mr.DataLabel(dl => dl.Visible(true).Position(Syncfusion.EJ2.Charts.LabelPosition.Top).Font(ff => ff.FontWeight("600").Color("#ffffff"))))
.DataSource(ViewBag.dataSource).Name("Tiger").Add();
}).PrimaryXAxis(px => px.Interval(1).MajorGridLines(mg=>mg.Width(0))
.LabelStyle(ls=>ls.Color("#ffffff")).TickPosition(Syncfusion.EJ2.Charts.AxisPosition.Inside)
.LabelPosition(Syncfusion.EJ2.Charts.AxisPosition.Inside).ValueType(Syncfusion.EJ2.Charts.ValueType.Category)
).PrimaryYAxis(py => py.Minimum(0).Maximum(300).Interval(50)
.MajorGridLines(mg => mg.Width(0)).LabelStyle(ls=>ls.Color("transparent"))
.MajorTickLines(mg => mg.Width(0)).LineStyle(mg => mg.Width(0))
).Title("Trade in Food Groups").ChartArea(area => area.Border(br=>br.Color("transparent"))
).Tooltip(tt => tt.Enable(false)).LegendSettings(lg => lg.Visible(false)
).Load("load").PointRender("pointRender").Loaded("loaded").Render()
</div>
<div style="float: right; margin-right: 10px;">
Source:
blogs.scientificamerican.com
</div>
</div>
<script>
var pointRender = function (args) {
var selectedTheme = location.hash.split('/')[1];
selectedTheme = selectedTheme ? selectedTheme : 'Material';
if (selectedTheme && selectedTheme.indexOf('fabric') > -1) {
args.fill = fabricColors[args.point.index % 10];
}
else if (selectedTheme === 'material') {
args.fill = materialColors[args.point.index % 10];
}
else {
args.fill = bootstrapColors[args.point.index % 10];
}
};
var count = 0;
var loaded = function (args) {
args.chart.loaded = null;
setInterval(
function () {
if (count === 0) {
args.chart.series[0].dataSource = [
{ x: 'Tea', y: 206, text: 'Bangaladesh' },
{ x: 'Misc', y: 123, text: 'Bhutn' },
{ x: 'Fish', y: 48, text: 'Nepal' },
{ x: 'Egg', y: 240, text: 'Thiland' },
{ x: 'Fruits', y: 170, text: 'Malaysia' }
];
args.chart.animate();
count++;
}
else if (count === 1) {
args.chart.series[0].dataSource = [
{ x: 'Tea', y: 86, text: 'Bangaladesh' },
{ x: 'Misc', y: 173, text: 'Bhutn' },
{ x: 'Fish', y: 188, text: 'Nepal' },
{ x: 'Egg', y: 109, text: 'Thiland' },
{ x: 'Fruits', y: 100, text: 'Malaysia' }
];
args.chart.animate();
count++;
}
else if (count === 2) {
args.chart.series[0].dataSource = [
{ x: 'Tea', y: 156, text: 'Bangaladesh' },
{ x: 'Misc', y: 33, text: 'Bhutn' },
{ x: 'Fish', y: 260, text: 'Nepal' },
{ x: 'Egg', y: 200, text: 'Thiland' },
{ x: 'Fruits', y: 30, text: 'Malaysia' }
];
args.chart.animate();
count = 0;
}
}, 2000);
}
</script>
}

Related

How to make the regression line through the origin in highcharts

I am trying to make the regression to start from the origin , x=y=0. Is this possible to do. some say it is not good to do so but for some purposes I need to make the line through the origin. I am using highcharts.
How about adding a point to the regression series with x = y = 0 and setting the marker to disabled in order to hide it?
let discipline = [
{
name: "Football",
data: "football"
}
];
Highcharts.getJSON(
"https://raw.githubusercontent.com/mekhatria/demo_highcharts/master/olympic2012.json?callback=?",
function (data) {
function regression(arrWeight, arrHeight) {
let r, sy, sx, b, a, meanX, meanY;
r = jStat.corrcoeff(arrHeight, arrWeight);
sy = jStat.stdev(arrWeight);
sx = jStat.stdev(arrHeight);
meanY = jStat(arrWeight).mean();
meanX = jStat(arrHeight).mean();
b = r * (sy / sx);
a = meanY - meanX * b;
//Set up a line
let y1, y2, x1, x2;
x1 = jStat.min(arrHeight);
x2 = jStat.max(arrHeight);
y1 = a + b * x1;
y2 = a + b * x2;
return {
line: [
//Add x = 0, y = 0 to your regression logic?
{x: 0, y: 0, marker: {enabled: false}},
{x: x1, y: y1, marker: {enabled: true}},
{x: x2, y: y2, marker: {enabled: true}},
],
r
};
}
const getData = (continentName) => {
let temp = [],
tempWeight = [],
tempHeight = [];
data.forEach((elm) => {
if (
elm.continent == continentName &&
elm.weight > 0 &&
elm.height > 0
) {
temp.push([elm.height, elm.weight]);
tempWeight.push(elm.weight);
tempHeight.push(elm.height);
}
});
let { line, r } = regression(tempWeight, tempHeight);
return [temp, line, r];
};
const getDataSport = (sportName) => {
let temp = [],
tempWeight = [],
tempHeight = [];
data.forEach((elm) => {
if (elm.sport == sportName && elm.weight > 0 && elm.height > 0) {
temp.push([elm.height, elm.weight]);
tempWeight.push(elm.weight);
tempHeight.push(elm.height);
}
});
let { line, r } = regression(tempWeight, tempHeight);
return [temp, line, r];
};
let series = [],
visible = false,
index = 0,
activate = ["Football"];
discipline.forEach((e) => {
if (activate.indexOf(e.name) > -1) {
visible = true;
} else {
visible = false;
}
let [scatterData, line, r] = getDataSport(e.data);
series.push(
{
type: "scatter",
visible: visible,
name: e.name,
data: scatterData
},
{
name: e.name,
visible: visible,
r: r,
data: line
}
);
});
Highcharts.chart("container", {
chart: {
type: "line",
zoomType: "y",
},
title: {
text: "2012 Olympic football athletes' weight and height relationship"
},
xAxis: {
title: {
text: "Height"
},
labels: {
format: "{value} m"
},
},
yAxis: {
title: {
text: "Weight"
},
labels: {
format: "{value} kg"
}
},
legend: {
enabled: true
},
plotOptions: {
scatter: {
marker: {
radius: 2.5,
symbol: "circle",
states: {
hover: {
enabled: true,
lineColor: "rgb(100,100,100)"
}
}
},
states: {
hover: {
marker: {
enabled: false
}
}
}
},
line: {
lineWidth: 2.5
}
},
tooltip: {
formatter: function () {
if (this.series.data.length > 2) {
return (
this.series.name +
"<br/>Height: " +
this.x +
" m<br/>Weight: " +
this.y +
" kg"
);
} else {
return (
this.series.name +
"<br/>r: " +
this.series.userOptions.r.toFixed(2)
);
}
}
},
series: series
});
}
);
<script src="https://code.highcharts.com/highcharts.js"></script>
<script src="https://code.highcharts.com/modules/data.js"></script>
<script src="https://code.highcharts.com/highcharts-more.js"></script>
<script src="https://code.highcharts.com/modules/export-data.js"></script>
<script src="https://code.highcharts.com/modules/accessibility.js"></script>
<script src="https://cdn.jsdelivr.net/npm/jstat#latest/dist/jstat.min.js"></script>
<script src="https://code.highcharts.com/modules/exporting.js"></script>
<div id="container"></div>

Highcharts gantt chart : Task progress indicator need to show a single task for various status like completed,inprogress etc with different colors

Refer the image
var markers = JSON.parse('<%=ConvertDataTabletoString("GetTaskWorkPercentage","2",null,1,10) %>');
var Arrayset = [];
var starts1 = [];
var ends1 = [];
var val1 = [];
var val2 = [];
if (markers != null) {
if (markers.length > 0) {
var prj = document.getElementById("param1").value;
for (var i = 0; i < markers.length; i++) {
var syearval = parseInt(markers[i].ActualStart.substr(0, 4));
var smonthval = parseInt(markers[i].ActualStart.substr(5, 2)) - 1;
var sdateval = parseInt(markers[i].ActualStart.substr(8, 2));
var eyearval = parseInt(markers[i].ActualEnd.substr(0, 4));
var emonthval = parseInt(markers[i].ActualEnd.substr(5, 2)) - 1;
var edateval = parseInt(markers[i].ActualEnd.substr(8, 2));
val1 = [Date.UTC(syearval, smonthval, sdateval)];
val2 = [Date.UTC(eyearval, emonthval, edateval)];
starts1.push(val1[0]);
ends1.push(val2[0]);
Arrayset.push({
name: markers[i].Task,
completed: markers[i].Percentages,
start: starts1[i],
end: ends1[i]
});
}
MainLoadChart(Arrayset);
}
}
function MainLoadChart(array) {
var dta = array;
Highcharts.ganttChart('container8', {
title: {
text: 'Task Progress Indicator Status'
},
tooltip: {
formatter()
{
//let output = `<span style="font-size: 10px">${this.point.series.name}</span><br>
let output = ` <span style="font-size: 20px;color:green">${prj}</span><br>
<span><b>${this.key}(Overall Subtask Percentage):${this.point.completed}% </b></span><br>
<span>Start: ${Highcharts.dateFormat('%A, %e. %b, %Y', this.x)}</span><br>
<span>End: ${Highcharts.dateFormat('%A, %e. %b, %Y', this.x2)}</span>`
return output
}
},
series: [{
data: dta,
dataLabels: {
formatter() {
//return this.point.completed;
let output1 = ` <span style="font-size: 10px">${this.point.completed}%</span>`
return output1
}
}]
});
}
Currently I´m showing the output of overall subtask. I need to show in a single task progress (overall) for various status like completed, inprogress, hold, returned with different (multiple) colors and style. So that values should not overlap or hide like datalabel values.
You should be able to achieve it by using yAxis.categories and assigning data to this one category.
Demo: https://jsfiddle.net/BlackLabel/19L48qy5/
...
yAxis: {
categories: ['Prototyping'],
},
series: [{
name: 'Project 1',
data: [{
name: 'test1',
start: Date.UTC(2014, 10, 18),
end: Date.UTC(2014, 10, 25),
y: 0
}, {
color: 'red',
name: 'test2',
start: Date.UTC(2014, 10, 18),
end: Date.UTC(2014, 10, 22),
y: 0
}, {
color: 'green',
name: 'test3',
start: Date.UTC(2014, 10, 18),
end: Date.UTC(2014, 10, 20),
y: 0
}]
}]
...
API: https://api.highcharts.com/gantt/yAxis.categories

Export Highcharts polar chart csv with categories in place of polar coordinates

I've implemented a polar chart in which each series has 4 values corresponding to 4 categories. When I export the chart csv, the category column contains polar coordinates. I would like to replace these with the corresponding category name. How do I do this?
Adding the categories to each series, had no effect. I also tried adding a categories property to the xAxis, but it had not effect. An xAxis.label formatter successfully returns the category name for each data polar coordinate.
const options = {
chart: {
polar: true,
},
title: {
text: '',
},
tooltip: {
valueDecimals: 2,
headerFormat: '<br/>',
},
legend: {},
pane: {
startAngle: 0,
endAngle: 360,
},
xAxis: {
tickInterval: 45,
min: 0,
max: 360,
labels: {
// eslint-disable-next-line
formatter: function() {
switch (this.value) {
case 45:
return '<b>Experience</b>'
case 135:
return '<b>Frictionless</b>'
case 225:
return '<b>Low Price</b>'
case 315:
return '<b>Brand</b>'
default:
return ''
}
},
},
},
yAxis: {
min: 0,
max: 10,
labels: {
format: '{}',
},
},
plotOptions: {
series: {
pointStart: 45,
pointInterval: 90,
},
column: {
pointPadding: 0,
groupPadding: 0,
},
},
series: kahnSeries,
}
You need to use categories property, but without options like: pointInterval, pointStart, min and max:
xAxis: {
categories: ['Experience', 'Frictionless', 'Low Price', 'Brand']
},
Live demo: http://jsfiddle.net/BlackLabel/z8cm1p39/
API Reference: https://api.highcharts.com/highcharts/xAxis.categories
To avoid changing the chart's current display, I wrapped the getCSV function and replaced the CSV category values. If there was a simpler way, please share it.
{
(function (H) {
H.wrap(H.Chart.prototype, 'getCSV', function (
proceed,
useLocalDecimalPoint
) {
// Run the original proceed method
const result = proceed.apply(
this,
Array.prototype.slice.call(arguments, 1)
)
const itemDelimiter = ','
const lineDelimiter = '\n'
const rows = result.split(lineDelimiter)
let newResult = ''
let rowCategories = false
rows.forEach((row, rowIndex) => {
const columns = row.split(itemDelimiter)
if (rowIndex === 0 && columns[0] === '"Category"') {
rowCategories = true
}
if (rowIndex > 0 && rowCategories) {
let newRow = formatter(columns[0])
columns.forEach((column, columnIndex) => {
if (columnIndex > 0) {
newRow += itemDelimiter
newRow += column
}
})
newResult += newRow
} else {
newResult += row
}
if (rowIndex < rows.length - 1) {
newResult += lineDelimiter
}
}
)
return newResult
})
}(Highcharts))
}

Highcharts y-axis unable to start from the given value

I am using high charts to generate graphs. As per my requirement I want to generate the graph with dynamic minimum and maximum values. Even though I assigned minimum and maximum value, my graph is starting from less than my minimum value. I want my graph to be start with the user defined minimum value such that no white space should be there between axis and graph
Following is the fiddle
http://jsfiddle.net/0e4rqb88/
$(document).ready(function() {
var data1 = [{
"maximumLean": 4.6,
"usl": 5.5,
"framesFlag": 0,
"emptyConesFlag": 0,
"ninetyFivePFlag": 0,
"sigma3": 4.8,
"sigma4": 4.4,
"sigma1": 4.6,
"arrow": 0,
"inSpec": 100.0,
"sigma2": 4.7,
"recentLean2": 4.600084552015582,
"recentLean1": 4.368252611538148,
"recentLean4": 4.369438416014055,
"recentLean3": 4.495304457897132,
"check2Sigma": 1,
"ninetyFivePValue": 0.1,
"meanFlag": 0,
"sigma6": 4.2,
"sigma5": 4.3,
"conesFlag": 0,
"targetSpec": 4.5,
"check3Sigma": 1,
"cpm": 1.1,
"emptyCone": 8.9,
"ninetyPFlag": 0,
"lsl": 3.5,
"sampleSize": 30,
"minimumLean": 4.4,
"check1Sigma": -1,
"ninetyPValue": 0.1,
"sd": 0.1,
"fpm": 1.0,
"fc": 123,
"lean": 4.4,
"median": 4.4,
"medianFlag": 0,
"inspecFlag": 0,
"cl": 4.5,
"sdFlag": 0,
"cc": 135
}, {
"lean": 4.5
}, {
"lean": 4.6
}, {
"lean": 4.4
}, {
"start": "08-12-2014 12:00:00",
"end": "08-12-2014 14:00:00"
}]
$('#data').val(JSON.stringify(data1[0]));
var x = 1;
var inSpec = 0;
var avgLean = 0;
var mean = 0;
var median = 0;
var sd = 0;
var maximum = 0;
var minimum = 0;
var sigma1 = 0;
var sigma2 = 0;
var sigma3 = 0;
var sigma4 = 0;
var sigma5 = 0;
var sigma6 = 0;
var avgLeanPercent = 0;
var sampleSize = 0;
//
var meandataofHighChart = 0;
var sigdata = [];
var dataofHighChart = [];
var maxChartVal = 0;
var minChartVal = 0;
for (var event in data1) {
var dataCopy = data1[event];
if (x == 1) {
mean = dataCopy.cl;
sd = dataCopy.sd;
median = dataCopy.median;
maximum = dataCopy.maximumLean;
minimum = dataCopy.minimumLean;
sigma1 = dataCopy.sigma1;
sigma2 = dataCopy.sigma2;
sigma3 = dataCopy.sigma3;
sigma4 = dataCopy.sigma4;
sigma5 = dataCopy.sigma5;
sigma6 = dataCopy.sigma6;
emptyCone = dataCopy.emptyCone;
sampleSize = dataCopy.sampleSize != undefined ? dataCopy.sampleSize : 20;
//alert(" Cone "+conesPerMinute.toFixed(1)+" Frame "+dataCopy.fpm);
sigdata.push(sigma6);
sigdata.push(sigma5);
sigdata.push(sigma4);
sigdata.push(mean);
sigdata.push(sigma1);
sigdata.push(sigma2);
sigdata.push(sigma3);
//dataofHighChart.push(lean);
}
dataofHighChart.push(dataCopy.lean);
meandataofHighChart = (mean);
x++;
}
maxChartVal = maximum > sigma3 ? maximum : sigma3;
minChartVal = minimum < sigma6 ? minimum : sigma6;
console.info("sigdata " + sigdata);
console.info("maximum " + maximum);
console.info("sigma3 " + sigma3);
console.info("minimum " + minimum);
console.info("sigma6 " + sigma6);
console.info("maxChartVal " + maxChartVal);
console.info("minChartVal " + minChartVal);
minChartVal = minChartVal > 0 ? (minChartVal) - 0.1000000000000005 : 0;
maxChartVal = maxChartVal > 0 ? (maxChartVal) + 0.1000000000000005 : 0;
console.info("maxChartVal " + maxChartVal);
console.info("minChartVal " + minChartVal);
var highchart = new Highcharts.Chart({
chart: {
marginRight: 80,
zoomType: "x",
renderTo: 'chart_div', // like ,
height: 350
},
title: {
text: 'X-Bar Chart',
style: {
"font-weight": "bold",
"font-size": "16px;"
}
},
xAxis: {
floor: 1,
allowDecimals: false,
title: {
text: "Sample Number (N = " + sampleSize + ")",
style: {
"font-weight": "bold",
"font-size": "14px;"
}
}
},
tooltip: {
formatter: function() {
return 'Sample Number : ' + this.point.x + '<br/> % Lean : ' + this.point.y + ' %';
}
},
yAxis: [{
lineWidth: 1,
max: maxChartVal,
min: minChartVal,
floor: minChartVal,
title: {
text: '% Lean',
style: {
"font-weight": "bold",
"font-size": "14px;"
}
},
plotLines: [{
value: meandataofHighChart,
color: '#000000',
width: 2,
zIndex: 4
}],
minorGridLineWidth: 0,
gridLineWidth: 0,
alternateGridColor: null,
plotBands: [{
from: minChartVal,
to: sigdata[1],
color: '#FF7F7F'
}, {
from: sigdata[1],
to: sigdata[2],
color: '#FFFF7F'
}, {
from: sigdata[2],
to: sigdata[3],
color: '#7FBF7F'
}, {
from: sigdata[3],
to: sigdata[4],
color: '#7FBF7F'
}, {
from: sigdata[4],
to: sigdata[5],
color: '#FFFF7F'
}, {
from: sigdata[5],
to: maxChartVal,
color: '#FF7F7F'
}]
}],
series: [{
name: '% Lean',
data: dataofHighChart,
color: '#00407F'
}]
});
});
By default, the startOnTick option and endOnTick option is true for the yAxis. If you set those to false, highcharts will respect your min/max options.
Here's updated fiddle.
yAxis: [{
...
max:maxChartVal,
min:minChartVal,
startOnTick: false,
endOnTick: false,
...

Google Combo Charts?

I have 4 entities and I show them for 4 days. But first and last days I cant see other 2 entities.In 3 August I cant see T0,T1. In 6 August I cant see T2,T3.
Codes
var evalledData = eval("(" + result.chartData + ")");
var ac = new google.visualization.ComboChart($("#chart_div_ay").get(0));
ac.draw(new google.visualization.DataTable(evalledData, 0.5), {
//title: 'Son 7 günlük sayaç okumalarının toplamı.',
width: '100%',
height: 300,
vAxis: { title: "kW" },
hAxis: { title: "Gün" },
seriesType: "bars",
series: { 5: { type: "line"} }
});
Controller:
public ActionResult MusteriSayaclariOkumalariChartDataTable(DateTime startDate, DateTime endDate, int? musteri_id)
{
IEnumerable<TblSayacOkumalari> sayac_okumalari = entity.TblSayacOkumalari;
var sonuc = from s in sayac_okumalari
where s.TblSayaclar.musteri_id == musteri_id && s.okuma_tarihi.Value >= startDate && s.okuma_tarihi.Value <= endDate
group s by new { date = new DateTime(((DateTime)s.okuma_tarihi).Year, ((DateTime)s.okuma_tarihi).Month, ((DateTime)s.okuma_tarihi).Day) } into g
select new
{
okuma_tarihi = g.Key,
T1 = g.Sum(x => x.kullanim_T1) / 1000,
T2 = g.Sum(x => x.kullanim_T2) / 1000,
T3 = g.Sum(x => x.kullanim_T3) / 1000,
T4 = g.Sum(x => x.kullanim_T0) / 1000
};
//Get your data table from DB or other source
DataTable chartTable = new DataTable();
chartTable.Columns.Add("Tarih").DataType = System.Type.GetType("System.DateTime");
chartTable.Columns.Add("T1").DataType = System.Type.GetType("System.Double");
chartTable.Columns.Add("T2").DataType = System.Type.GetType("System.Double");
chartTable.Columns.Add("T3").DataType = System.Type.GetType("System.Double");
chartTable.Columns.Add("Toplam").DataType = System.Type.GetType("System.Double");
foreach (var item in sonuc)
{
chartTable.Rows.Add(item.okuma_tarihi.date, item.T1.Value, item.T2.Value, item.T3.Value, item.T4.Value);
}
//convert datetime value to google datetype, if your first column is date
Bortosky
.Google
.Visualization
.GoogleDataTable
.SetGoogleDateType(chartTable.Columns["Tarih"],
Bortosky.Google.Visualization.GoogleDateType.Date);
//convert DataTable to GoogleDataTable
var googleDataTable =
new Bortosky.Google.Visualization.GoogleDataTable(chartTable);
//Pass the google datatable to UI as json string
return new JsonResult
{
Data = new
{
success = true,
chartData = googleDataTable.GetJson()
},
JsonRequestBehavior = JsonRequestBehavior.AllowGet
};
}
This action return json as google examples custom data.
evalledData output:
Is there any option about this problem?
Thanks.
I recently had to build a chart like this. Please consider my code for your solution:
Put this in your Controller:
<EmployeeAuthorize()>
Function WeightAreaChartData() As JsonResult
Dim myData = db.Tbl_Weights.Where(Function(x) x.Weight_Employee_ID).OrderBy(Function(x) x.Weight_Create_Date)
Dim data = New List(Of Object)
data.Add(New Object() {"Date", "Your Weight"})
For Each i As Tbl_Weight In myData
data.Add(New Object() {DateTime.Parse(i.Weight_Create_Date).Day, i.Weight_Amount})
Next
Return Json(data, JsonRequestBehavior.AllowGet)
End Function
Put this in your view; changing the $.post() URL accordingly:
<script type="text/javascript">
google.load("visualization", "1", { packages: ["corechart"] });
google.setOnLoadCallback(drawChart);
function drawChart() {
$.post('/Weight/WeightAreaChartData', {},
function (data) {
var tdata = new google.visualization.arrayToDataTable(data);
var options = {
title: 'Weight Lost & Gained This Month',
hAxis: { title: 'Day of Month', titleTextStyle: { color: '#1E4A08'} },
vAxis: { title: 'Lbs.', titleTextStyle: { color: '#1E4A08'} },
chartArea: { left: 50, top: 30, width: "75%" },
colors: ['#FF8100']
};
var chart = new google.visualization.ColumnChart(document.getElementById('chart_div'));
chart.draw(tdata, options);
});
}
</script>
<div id="chart_div" style="width: 580px; height: 200px;"></div>
To fix your specific issue of the bars being cut off, I believe you can use this in your options:
hAxis: {
viewWindowMode: 'pretty'
}
Like this:
var options = {
title: 'Weight Lost & Gained This Month',
hAxis: { title: 'Day of Month', titleTextStyle: { color: '#1E4A08'} },
vAxis: { title: 'Lbs.', titleTextStyle: { color: '#1E4A08' } },
chartArea: { left: 50, top: 30, width: "75%" },
colors: ['#FF8100', 'blue'],
hAxis: {
viewWindowMode: 'pretty'
}
};

Resources