Gallery
JS Web Service Csv Data
<%@ Page Language="C#" Description="dotnetCHARTING Component" %>
<%@ Register TagPrefix="dnc" Namespace="dotnetCHARTING" Assembly="dotnetCHARTING"%>
<%@ Import Namespace="System.Drawing" %>
<script runat="server">
void Page_Load(Object sender,EventArgs e)
{
// Demonstrates Line chart using Csv data file.
Chart.Type = ChartType.Combo;
Chart.DefaultSeries.Type = SeriesType.Line;
Chart.Width = 740;
Chart.Height = 400;
Chart.TempDirectory = "temp";
Chart.Debug = false;
Chart.TitleBox.Label.Text = "Average Life Expectancy (Years)";
Chart.DefaultSeries.DefaultElement.Marker.Type = ElementMarkerType.None;
//JS settings
Chart.JS.Enabled = true;
Chart.JS.RenderCallback = "updateChart";
Chart.XAxis.FormatString = "yyyy";
Chart.XAxis.Scale = Scale.Time;
// Style Legend
Chart.LegendBox.Position = LegendBoxPosition.ChartArea;
Chart.LegendBox.ClearColors();
Chart.LegendBox.DefaultEntry.LabelStyle.Font = new Font("Tahoma", 11, FontStyle.Bold);
Chart.LegendBox.DefaultEntry.LabelStyle.Color = Color.Black;
Annotation an = new Annotation();
an.Padding = 8;
an.Label.Text = "Source: Centers for Disease Control and Prevention";
an.Orientation = dotnetCHARTING.Orientation.Bottom;
an.ClearColors();
Chart.Annotations.Add(an);
Chart.JS.Settings.Add("annotations.0.position", "bottom");
Chart.JS.Settings.Add("defaultSeries.states.hover.line.width", "2");
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>.netCHARTING Sample</title>
</head>
<body>
<dnc:Chart ID="Chart" runat="server" style="max-width:740px;margin:0px auto;"/>
<script type="text/javascript">
function updateChart(ch) { loadData(ch, makeChart); };
function loadData(chart, cb){
JSC.fetch('https://data.cdc.gov/api/views/w9j2-ggv5/rows.csv?accessType=DOWNLOAD')
.then(function(response) { return response.text() })
.then(function(text) {
var parsed = JSC.parseCsv(text);
cb(chart,parsed.data)
})
.catch(function(err) { console.error(err) });
}
function makeChart(chart,data) {
//Format csv data into points that will bind the calendar cells.
//Filter out unused data
var allRaces = data.filter(function (row) { return row[1] === 'All Races'; });
var male = allRaces.filter(function (row) { return row[2] === 'Male'; });
var female = allRaces.filter(function (row) { return row[2] === 'Female'; });
var toPoints = function (rows) {
return rows.map(function (row) {
return { x: '1/1/' + row[0], y: row[3] }
});
}
//Add data to chart.
chart.series.add({
name: 'Male',
points: toPoints(male)
});
chart.series.add({
name: 'Female',
points: toPoints(female)
});
}
</script>
</body>
</html>
<%@ Page Language="vb" Description="dotnetCHARTING Component" %>
<%@ Register TagPrefix="dnc" Namespace="dotnetCHARTING" Assembly="dotnetCHARTING"%>
<%@ Import Namespace="System.Drawing" %>
<script runat="server">
Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
' Demonstrates Line chart using Csv data file.
Chart.Type = ChartType.Combo
Chart.DefaultSeries.Type = SeriesType.Line
Chart.Width = 740
Chart.Height = 400
Chart.TempDirectory = "temp"
Chart.Debug = False
Chart.TitleBox.Label.Text = "Average Life Expectancy (Years)"
Chart.DefaultSeries.DefaultElement.Marker.Type = ElementMarkerType.None
'JS settings
Chart.JS.Enabled = True
Chart.JS.RenderCallback = "updateChart"
Chart.XAxis.FormatString = "yyyy"
Chart.XAxis.Scale = Scale.Time
' Style Legend
Chart.LegendBox.Position = LegendBoxPosition.ChartArea
Chart.LegendBox.ClearColors()
Chart.LegendBox.DefaultEntry.LabelStyle.Font = New Font("Tahoma", 11, FontStyle.Bold)
Chart.LegendBox.DefaultEntry.LabelStyle.Color = Color.Black
Dim an As Annotation = New Annotation()
an.Padding = 8
an.Label.Text = "Source: Centers for Disease Control and Prevention"
an.Orientation = dotnetCHARTING.Orientation.Bottom
an.ClearColors()
Chart.Annotations.Add(an)
Chart.JS.Settings.Add("annotations.0.position", "bottom")
Chart.JS.Settings.Add("defaultSeries.states.hover.line.width", "2")
End Sub
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>.netCHARTING Sample</title>
</head>
<body>
<dnc:Chart ID="Chart" runat="server" style="max-width:740px;margin:0px auto;"/>
<script type="text/javascript">
function updateChart(ch) { loadData(ch, makeChart); };
function loadData(chart, cb){
JSC.fetch('https://data.cdc.gov/api/views/w9j2-ggv5/rows.csv?accessType=DOWNLOAD')
.then(function(response) { return response.text() })
.then(function(text) {
var parsed = JSC.parseCsv(text);
cb(chart,parsed.data)
})
.catch(function(err) { console.error(err) });
}
function makeChart(chart,data) {
//Format csv data into points that will bind the calendar cells.
//Filter out unused data
var allRaces = data.filter(function (row) { return row[1] === 'All Races'; });
var male = allRaces.filter(function (row) { return row[2] === 'Male'; });
var female = allRaces.filter(function (row) { return row[2] === 'Female'; });
var toPoints = function (rows) {
return rows.map(function (row) {
return { x: '1/1/' + row[0], y: row[3] }
});
}
//Add data to chart.
chart.series.add({
name: 'Male',
points: toPoints(male)
});
chart.series.add({
name: 'Female',
points: toPoints(female)
});
}
</script>
</body>
</html>
- Sample FilenameJsWebServiceCsvData.aspx
- Version9.1
- Uses DatabaseNo